From 7fc03ac954f112af3bb97b9e37860da401a94189 Mon Sep 17 00:00:00 2001 From: Tobias Zander Date: Thu, 29 May 2014 12:07:31 +0200 Subject: [PATCH 1/2] set changed status on model to prevent status overwriting when model gets saved --- app/code/Magento/Cron/Model/Schedule.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/Model/Schedule.php b/app/code/Magento/Cron/Model/Schedule.php index c8666ea6545b1..5ab7518a42070 100644 --- a/app/code/Magento/Cron/Model/Schedule.php +++ b/app/code/Magento/Cron/Model/Schedule.php @@ -257,10 +257,14 @@ public function getNumeric($value) */ public function tryLockJob() { - return $this->_getResource()->trySetJobStatusAtomic( + if ($this->_getResource()->trySetJobStatusAtomic( $this->getId(), self::STATUS_RUNNING, self::STATUS_PENDING - ); + )) { + $this->setStatus(self::STATUS_RUNNING); + return true; + } + return false; } } From 4678e584c389e96ca4f5e899a883bdeb32621ea0 Mon Sep 17 00:00:00 2001 From: Tobias Zander Date: Fri, 30 May 2014 11:39:27 +0200 Subject: [PATCH 2/2] remove obsolete setting of status as it's now fixed in the model --- app/code/Magento/Cron/Model/Observer.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/code/Magento/Cron/Model/Observer.php b/app/code/Magento/Cron/Model/Observer.php index 5fdb903578597..d48ba93735983 100644 --- a/app/code/Magento/Cron/Model/Observer.php +++ b/app/code/Magento/Cron/Model/Observer.php @@ -223,11 +223,7 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule, ); } - /** - * though running status is set in tryLockJob we must set it here because the object - * was loaded with a pending status and will set it back to pending if we don't set it here - */ - $schedule->setStatus(Schedule::STATUS_RUNNING)->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', time()))->save(); + $schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', time()))->save(); call_user_func_array($callback, array($schedule));