Aoe_Scheduler - Version 0.1.3

Version Notes

Bugfix release.

Download this release

Release Info

Developer Magento Core Team
Extension Aoe_Scheduler
Version 0.1.3
Comparing to
See all releases


Code changes from version 0.1.2 to 0.1.3

app/code/local/Aoe/Scheduler/Model/Observer.php CHANGED
@@ -82,9 +82,12 @@ class Aoe_Scheduler_Model_Observer extends Mage_Cron_Model_Observer {
82
  $schedule->setMessages($messages);
83
  }
84
 
85
- $schedule
86
- ->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS)
87
- ->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
 
 
 
88
 
89
  } catch (Exception $e) {
90
  $schedule->setStatus($errorStatus)
82
  $schedule->setMessages($messages);
83
  }
84
 
85
+ if (strtoupper(substr($messages, 0, 6)) != 'ERROR:') {
86
+ $schedule->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS);
87
+ } else {
88
+ $schedule->setStatus(Mage_Cron_Model_Schedule::STATUS_ERROR);
89
+ }
90
+ $schedule->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
91
 
92
  } catch (Exception $e) {
93
  $schedule->setStatus($errorStatus)
app/code/local/Aoe/Scheduler/Model/Schedule.php CHANGED
@@ -20,9 +20,10 @@ class Aoe_Scheduler_Model_Schedule extends Mage_Cron_Model_Schedule {
20
  /**
21
  * Run this task now
22
  *
 
23
  * @return Aoe_Scheduler_Model_Schedule
24
  */
25
- public function runNow() {
26
  $modelCallback = $this->getJobConfiguration()->getModel();
27
 
28
  if (!$this->getCreatedAt()) {
@@ -41,24 +42,33 @@ class Aoe_Scheduler_Model_Schedule extends Mage_Cron_Model_Schedule {
41
  Mage::throwException(Mage::helper('cron')->__('No callbacks found'));
42
  }
43
 
44
- if (!$this->tryLockJob()) {
 
 
45
  // another cron started this job intermittently, so skip it
46
  return $this;
47
  }
48
  $this->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
49
 
50
- $messages = call_user_func_array($callback, array());
51
 
52
- // added by Fabrizio to also save messages when no exception was thrown
53
- if (!empty($messages)) {
54
- if (!is_string($messages)) {
55
- $messages = var_export($messages, 1);
56
- }
57
- $this->setMessages($messages);
58
- }
 
 
 
 
 
 
 
 
59
 
60
- $this->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS)
61
- ->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
62
 
63
  return $this;
64
  }
20
  /**
21
  * Run this task now
22
  *
23
+ * @param bool $tryLockJob
24
  * @return Aoe_Scheduler_Model_Schedule
25
  */
26
+ public function runNow($tryLockJob=true) {
27
  $modelCallback = $this->getJobConfiguration()->getModel();
28
 
29
  if (!$this->getCreatedAt()) {
42
  Mage::throwException(Mage::helper('cron')->__('No callbacks found'));
43
  }
44
 
45
+ // lock job requires the record to be saved and having status Mage_Cron_Model_Schedule::STATUS_PENDING
46
+ // workaround could be to do this: $this->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING)->save();
47
+ if ($tryLockJob && !$this->tryLockJob()) {
48
  // another cron started this job intermittently, so skip it
49
  return $this;
50
  }
51
  $this->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
52
 
53
+ $messages = call_user_func_array($callback, array());
54
 
55
+ // added by Fabrizio to also save messages when no exception was thrown
56
+ if (!empty($messages)) {
57
+ if (is_object($messages)) {
58
+ $messages = get_class($messages);
59
+ } elseif (!is_scalar($messages)) {
60
+ $messages = var_export($messages, 1);
61
+ }
62
+ $this->setMessages($messages);
63
+ }
64
+
65
+ if (strtoupper(substr($messages, 0, 6)) != 'ERROR:') {
66
+ $this->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS);
67
+ } else {
68
+ $this->setStatus(Mage_Cron_Model_Schedule::STATUS_ERROR);
69
+ }
70
 
71
+ $this->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
 
72
 
73
  return $this;
74
  }
app/code/local/Aoe/Scheduler/controllers/Adminhtml/CronController.php CHANGED
@@ -61,12 +61,14 @@ class Aoe_Scheduler_Adminhtml_CronController extends Aoe_Scheduler_Adminhtml_Abs
61
  */
62
  public function scheduleNowAction() {
63
  $codes = $this->getRequest()->getParam('codes');
64
- foreach ($codes as $key) {
65
- Mage::getModel('cron/schedule') /* @var Aoe_Scheduler_Model_Schedule */
66
- ->setJobCode($key)
67
- ->scheduleNow()
68
- ->save();
69
- Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Scheduled "%s"', $key));
 
 
70
  }
71
  $this->_redirect('*/*/index');
72
  }
@@ -80,12 +82,28 @@ class Aoe_Scheduler_Adminhtml_CronController extends Aoe_Scheduler_Adminhtml_Abs
80
  */
81
  public function runNowAction() {
82
  $codes = $this->getRequest()->getParam('codes');
83
- foreach ($codes as $key) {
84
- $schedule = Mage::getModel('cron/schedule') /* @var $schedule Aoe_Scheduler_Model_Schedule */
85
- ->setJobCode($key)
86
- ->runNow()
87
- ->save();
88
- Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Ran "%s" (Duration: %s sec)', $key, $schedule->getDuration()));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
  $this->_redirect('*/*/index');
91
  }
61
  */
62
  public function scheduleNowAction() {
63
  $codes = $this->getRequest()->getParam('codes');
64
+ if (is_array($codes)) {
65
+ foreach ($codes as $key) {
66
+ Mage::getModel('cron/schedule') /* @var Aoe_Scheduler_Model_Schedule */
67
+ ->setJobCode($key)
68
+ ->scheduleNow()
69
+ ->save();
70
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Scheduled "%s"', $key));
71
+ }
72
  }
73
  $this->_redirect('*/*/index');
74
  }
82
  */
83
  public function runNowAction() {
84
  $codes = $this->getRequest()->getParam('codes');
85
+ if (is_array($codes)) {
86
+ foreach ($codes as $key) {
87
+ $schedule = Mage::getModel('cron/schedule') /* @var $schedule Aoe_Scheduler_Model_Schedule */
88
+ ->setJobCode($key)
89
+ ->runNow(false) // without trying to lock the job
90
+ ->save();
91
+
92
+ $messages = $schedule->getMessages();
93
+
94
+ if ($schedule->getStatus() == Mage_Cron_Model_Schedule::STATUS_SUCCESS) {
95
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Ran "%s" (Duration: %s sec)', $key, intval($schedule->getDuration())));
96
+ if ($messages) {
97
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('"%s" messages:<pre>%s</pre>', $key, $messages));
98
+ }
99
+ } else {
100
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Error while running "%s"', $key));
101
+ if ($messages) {
102
+ Mage::getSingleton('adminhtml/session')->addError($this->__('"%s" messages:<pre>%s</pre>', $key, $messages));
103
+ }
104
+ }
105
+
106
+ }
107
  }
108
  $this->_redirect('*/*/index');
109
  }
app/code/local/Aoe/Scheduler/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Aoe_Scheduler>
5
- <version>0.1.2</version>
6
  </Aoe_Scheduler>
7
  </modules>
8
 
2
  <config>
3
  <modules>
4
  <Aoe_Scheduler>
5
+ <version>0.1.3</version>
6
  </Aoe_Scheduler>
7
  </modules>
8
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Aoe_Scheduler</name>
4
- <version>0.1.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -10,9 +10,9 @@
10
  <description>This extension allows you to manage your scheduler task. Schedules can be disabled. From version 0.1.0 this extension also comes with a graphical timeline view.</description>
11
  <notes>Bugfix release.</notes>
12
  <authors><author><name>Fabrizio Branca</name><user>auto-converted</user><email>magento@fabrizio-branca.de</email></author></authors>
13
- <date>2011-09-13</date>
14
- <time>18:24:16</time>
15
- <contents><target name="magelocal"><dir name="Aoe"><dir name="Scheduler"><dir name="Block"><dir name="Adminhtml"><dir name="Cron"><file name="Grid.php" hash="794200ea4a6885a19b86c972d06b3693"/></dir><dir name="Scheduler"><file name="Grid.php" hash="73eb69714d3ec1a6b3e5ceb566067ad1"/></dir><file name="Cron.php" hash="457cf34ffe0fde57ce3bd200d9661507"/><file name="Scheduler.php" hash="63229aa4b83993934252c23e6e9c0945"/><file name="Timeline.php" hash="f8f8cebf664d74e970cb8f4b01785b8f"/><file name="TimelineDetail.php" hash="791ffc9beaf7317631d9bc7ed7519239"/></dir></dir><dir name="Helper"><file name="Data.php" hash="9ba5f7c21da1a226e531162b9e9622d2"/></dir><dir name="Model"><dir name="Collection"><file name="Crons.php" hash="733ae06d490b4b371d70ee275bd3a3a9"/></dir><file name="Configuration.php" hash="1c21f0c4fa50cd4980fe1bdb7e4956f3"/><file name="Observer.php" hash="d63cc90d51f743c5b81c39f6ee23ef01"/><file name="Schedule.php" hash="756baf06064a7a8960705dc40f6f3e9b"/><file name="TestTask.php" hash="96ac1c00c24cf959cbef452dd57900e4"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="AbstractController.php" hash="4435f29815e4253eb47f15221b5c0d43"/><file name="CronController.php" hash="4e8116c26b36c1d9469a2b220e23baeb"/><file name="SchedulerController.php" hash="95ffe62214e872e566332de6a2141cab"/><file name="TimelineController.php" hash="c0ccb4163c8495c9b8b07a869e27563b"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="42f04275451a6837516cdcef0a14c40b"/><file name="config.xml" hash="4894b883b80677f870739b3eba076dcc"/><file name="system.xml" hash="fa7247753c1df15c8bdf5a9f76d9b712"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aoe_Scheduler.xml" hash="3fa179507d5b3b3f1cde3be281ee1a26"/></dir></target><target name="mage"><dir name="shell"><file name="scheduler.php" hash="1d9ab318d9cc13448cd93a99038f9b3b"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Aoe_Scheduler.csv" hash="f06c379c1170bc67f978b05943197601"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="aoe_scheduler"><file name="timeline.phtml" hash="7e2a11d5516206f219e4f5286b9c8656"/><file name="timeline_detail.phtml" hash="d353689ad539f2adc0df97716ff7eb88"/></dir></dir><dir name="layout"><dir name="aoe_scheduler"><file name="aoe_scheduler.xml" hash="95be2d020b3281f3400a2edb809fce79"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="aoe_scheduler"><dir name="Images"><file name="bg_notifications.gif" hash="df73b8aa7e48bb56e0a644245aa3683f"/><file name="gradient.png" hash="17f6c6ef64b1682a06060950933561c9"/><file name="hour.gif" hash="91a63b82b2b41a046ca938aea3238a41"/></dir><dir name="JavaScript"><file name="common.js" hash="af6dadb7e3a18a2d4a882d9249f3f7a0"/><file name="jquery-1.6.2.min.js" hash="a1a8cb16a060f6280a767187fd22e037"/><file name="tooltip.dynamic.js" hash="c6737dd54890ca0cac816f3fecaf33d9"/><file name="tooltip.js" hash="d731eecbe152f86d3c702b55b4767fb1"/></dir><dir name="StyleSheet"><file name="bars.css" hash="c98df4a3611f628dba01b8cd0142f3d2"/><file name="timeline.css" hash="41510bd533aaeab5df46fa49210cfc9f"/></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Aoe_Scheduler</name>
4
+ <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
10
  <description>This extension allows you to manage your scheduler task. Schedules can be disabled. From version 0.1.0 this extension also comes with a graphical timeline view.</description>
11
  <notes>Bugfix release.</notes>
12
  <authors><author><name>Fabrizio Branca</name><user>auto-converted</user><email>magento@fabrizio-branca.de</email></author></authors>
13
+ <date>2011-10-06</date>
14
+ <time>21:06:39</time>
15
+ <contents><target name="magelocal"><dir name="Aoe"><dir name="Scheduler"><dir name="Block"><dir name="Adminhtml"><dir name="Cron"><file name="Grid.php" hash="794200ea4a6885a19b86c972d06b3693"/></dir><dir name="Scheduler"><file name="Grid.php" hash="73eb69714d3ec1a6b3e5ceb566067ad1"/></dir><file name="Cron.php" hash="457cf34ffe0fde57ce3bd200d9661507"/><file name="Scheduler.php" hash="63229aa4b83993934252c23e6e9c0945"/><file name="Timeline.php" hash="f8f8cebf664d74e970cb8f4b01785b8f"/><file name="TimelineDetail.php" hash="791ffc9beaf7317631d9bc7ed7519239"/></dir></dir><dir name="Helper"><file name="Data.php" hash="9ba5f7c21da1a226e531162b9e9622d2"/></dir><dir name="Model"><dir name="Collection"><file name="Crons.php" hash="733ae06d490b4b371d70ee275bd3a3a9"/></dir><file name="Configuration.php" hash="1c21f0c4fa50cd4980fe1bdb7e4956f3"/><file name="Observer.php" hash="e9f408fa047eb798ca8856ade9984e8d"/><file name="Schedule.php" hash="dee187f972e294eeb1954dc6e049c1d3"/><file name="TestTask.php" hash="96ac1c00c24cf959cbef452dd57900e4"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="AbstractController.php" hash="4435f29815e4253eb47f15221b5c0d43"/><file name="CronController.php" hash="8cc4e61d1dfeeebfc7db4427523ba0d1"/><file name="SchedulerController.php" hash="95ffe62214e872e566332de6a2141cab"/><file name="TimelineController.php" hash="c0ccb4163c8495c9b8b07a869e27563b"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="42f04275451a6837516cdcef0a14c40b"/><file name="config.xml" hash="843bddb9cbf91210105cd1538adeabc9"/><file name="system.xml" hash="fa7247753c1df15c8bdf5a9f76d9b712"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aoe_Scheduler.xml" hash="3fa179507d5b3b3f1cde3be281ee1a26"/></dir></target><target name="mage"><dir name="shell"><file name="scheduler.php" hash="1d9ab318d9cc13448cd93a99038f9b3b"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Aoe_Scheduler.csv" hash="f06c379c1170bc67f978b05943197601"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="aoe_scheduler"><file name="timeline.phtml" hash="7e2a11d5516206f219e4f5286b9c8656"/><file name="timeline_detail.phtml" hash="d353689ad539f2adc0df97716ff7eb88"/></dir></dir><dir name="layout"><dir name="aoe_scheduler"><file name="aoe_scheduler.xml" hash="95be2d020b3281f3400a2edb809fce79"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="aoe_scheduler"><dir name="Images"><file name="bg_notifications.gif" hash="df73b8aa7e48bb56e0a644245aa3683f"/><file name="gradient.png" hash="17f6c6ef64b1682a06060950933561c9"/><file name="hour.gif" hash="91a63b82b2b41a046ca938aea3238a41"/></dir><dir name="JavaScript"><file name="common.js" hash="af6dadb7e3a18a2d4a882d9249f3f7a0"/><file name="jquery-1.6.2.min.js" hash="a1a8cb16a060f6280a767187fd22e037"/><file name="tooltip.dynamic.js" hash="c6737dd54890ca0cac816f3fecaf33d9"/><file name="tooltip.js" hash="d731eecbe152f86d3c702b55b4767fb1"/></dir><dir name="StyleSheet"><file name="bars.css" hash="c98df4a3611f628dba01b8cd0142f3d2"/><file name="timeline.css" hash="41510bd533aaeab5df46fa49210cfc9f"/></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>