magento2-CronjobManager
magento2-CronjobManager copied to clipboard
Edit Cron Group of Individual Job
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.
Oh my goodness, 1000% this
Yes would be a big plus
Ooo interesting. I might pick this one up.
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.
@fredden any thoughts?