Skip to content

Commit 8ffa191

Browse files
author
Anton Evers
committed
Change the order or run, schedule, cleanup to cleanup, schedule, run
This is in preparation of listening for changes in the configuration to check if a scheduled cron job is still enabled. When you disable a cron job in te config and flush the config cache, the cron observer should remove any scheduled cron jobs that are pending. If the cron observer runs the jobs before cleaning up, cron jobs that have been disabled will still run 1 time before they are removed from the schedule after disabling them. The extra advantage of this setup is that cron jobs will run directly after they have been scheduled, in the same run. So you don't have to run the cron job twice to see jobs executing. One for scheduling and one for running. If there is a perfectly good reason not to generate the schedule and clean jobs before running them I would very much like to know.
1 parent a3ca437 commit 8ffa191

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
176176
$phpPath = $this->phpExecutableFinder->find() ?: 'php';
177177

178178
foreach ($jobGroupsRoot as $groupId => $jobsRoot) {
179+
$this->cleanup($groupId);
180+
$this->generate($groupId);
179181
if ($this->request->getParam('group') !== null
180182
&& $this->request->getParam('group') !== '\'' . ($groupId) . '\''
181183
&& $this->request->getParam('group') !== $groupId) {
@@ -232,9 +234,6 @@ public function execute(\Magento\Framework\Event\Observer $observer)
232234
}
233235
$schedule->save();
234236
}
235-
236-
$this->generate($groupId);
237-
$this->cleanup($groupId);
238237
}
239238
}
240239

0 commit comments

Comments
 (0)