Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Cron Group of Individual Job #151

Open
tdorchak opened this issue Jul 24, 2020 · 5 comments
Open

Edit Cron Group of Individual Job #151

tdorchak opened this issue Jul 24, 2020 · 5 comments

Comments

@tdorchak
Copy link

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.

@maderlock
Copy link

Oh my goodness, 1000% this

@onlinebizsoft
Copy link

Yes would be a big plus

@peterjaap
Copy link

Ooo interesting. I might pick this one up.

@peterjaap
Copy link

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
Copy link

@fredden any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants