Skip to content

Commit

Permalink
Added methods to support "error state" for cron schedule (#3310)
Browse files Browse the repository at this point in the history
* Check if cron is on error

* Add method getIsError

* added return type as suggested by @sreichel

---------

Co-authored-by: Fabrizio Balliano <[email protected]>
  • Loading branch information
luigifab and fballiano authored Jun 22, 2023
1 parent 0992d8c commit ea2fa76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/code/core/Mage/Cron/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ protected function _processJob($schedule, $jobConfig, $isAlways = false)
$schedule->setStatus($errorStatus)
->setMessages($e->__toString());
}

if ($schedule->getIsError()) {
$schedule->setStatus(Mage_Cron_Model_Schedule::STATUS_ERROR);
}

$schedule->save();

return $this;
Expand Down
9 changes: 9 additions & 0 deletions app/code/core/Mage/Cron/Model/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @method Mage_Cron_Model_Resource_Schedule _getResource()
* @method Mage_Cron_Model_Resource_Schedule getResource()
* @method Mage_Cron_Model_Resource_Schedule_Collection getCollection()
* @method $this setIsError(bool $value)
* @method string getJobCode()
* @method $this setJobCode(string $value)
* @method string getStatus()
Expand Down Expand Up @@ -53,6 +54,14 @@ public function _construct()
$this->_init('cron/schedule');
}

/**
* @return bool
*/
public function getIsError(): bool
{
return !empty($this->getData('is_error'));
}

/**
* @param string $expr
* @return $this
Expand Down

0 comments on commit ea2fa76

Please sign in to comment.