magento2-CronjobManager icon indicating copy to clipboard operation
magento2-CronjobManager copied to clipboard

Edit Cron Group of Individual Job

Open tdorchak opened this issue 3 years ago • 5 comments

It would be great to have the ability to move a job to another cron group the same way you can edit an individual cron's schedule. Many 3rd party modules carelessly add their long running crons to the default or index group resulting in important lightweight jobs getting missed. Magento doesn't seem to have a clean way to move jobs to other groups so adding this feature would be a huge win in my opinion.

tdorchak avatar Jul 24 '20 10:07 tdorchak

Oh my goodness, 1000% this

maderlock avatar Mar 23 '21 16:03 maderlock

Yes would be a big plus

onlinebizsoft avatar Mar 14 '23 14:03 onlinebizsoft

Ooo interesting. I might pick this one up.

peterjaap avatar Nov 21 '23 16:11 peterjaap

Here's one approach, that does it through adding another config; https://github.com/AydinHassan/m2-cron-job-modify/tree/master

It uses a plugin on the Magento cron config class;

    <type name="Magento\Cron\Model\Config">
        <plugin disabled="false" name="modify_cron_jobs" type="TrashPanda\CronJobModifier\Plugin\ModifyCronJobs"/>
    </type>

There it has a an afterGetJobs function;

    public function afterGetJobs(Config $subject, array $jobs): array
    {
        $jobs = $this->moveJobGroups($jobs);

        return $jobs;
    }

And the function that moves the cron job to another group;

    private function moveJobGroups(array $jobs): array
    {
        foreach ($jobs as $group => $groupJobs) {
            $moves = $this->config->getJobsToMoveForGroup($group);

            foreach ($moves as $job => $destinationGroup) {
                if (isset($jobs[$destinationGroup]) && isset($groupJobs[$job])) {
                    $jobs[$destinationGroup][$job] = $groupJobs[$job];
                    unset($jobs[$group][$job]);
                }
            }
        }


        return $jobs;
    }

We could do something similar, by adding a dropdown to the cronjobmanager/config/edit page which lists all cron groups. We could then fetch that configuration in the moveJobGroups plugin and basically perform the same trick.

peterjaap avatar Nov 21 '23 20:11 peterjaap

@fredden any thoughts?

peterjaap avatar Nov 28 '23 08:11 peterjaap