| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,11 @@ function after($event = array()) { | |||
| 39 | 39 | 'type' => 'datetime', | |
| 40 | 40 | 'null' => false | |
| 41 | 41 | ), | |
| 42 | + 'notbefore' => array( | ||
| 43 | + 'type' => 'datetime', | ||
| 44 | + 'null' => true, | ||
| 45 | + 'default' => NULL | ||
| 46 | + ), | ||
| 42 | 47 | 'fetched' => array( | |
| 43 | 48 | 'type' => 'datetime', | |
| 44 | 49 | 'null' => true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,11 +18,16 @@ class QueuedTask extends AppModel { | |||
| 18 | 18 | * @param array $data any array | |
| 19 | 19 | * @return bool success | |
| 20 | 20 | */ | |
| 21 | - public function createJob($jobName, $data) { | ||
| 22 | - return ($this->save($this->create(array( | ||
| 21 | + public function createJob($jobName, $data, $notBefore = null) { | ||
| 22 | + | ||
| 23 | + $data = array( | ||
| 23 | 24 | 'jobtype' => $jobName, | |
| 24 | 25 | 'data' => serialize($data) | |
| 25 | - )))); | ||
| 26 | + ); | ||
| 27 | + if ($notBefore != null) { | ||
| 28 | + $data['notbefore'] = date('Y-m-d H:i:s', strtotime($notBefore)); | ||
| 29 | + } | ||
| 30 | + return ($this->save($this->create($data))); | ||
| 26 | 31 | } | |
| 27 | 32 | ||
| 28 | 33 | /** | |
@@ -43,9 +48,19 @@ public function requestJob($capabilities) { | |||
| 43 | 48 | foreach ($capabilities as $task) { | |
| 44 | 49 | $findConf['conditions']['OR'][] = array( | |
| 45 | 50 | 'jobtype' => str_replace('queue_', '', $task['name']), | |
| 46 | - 'OR' => array( | ||
| 47 | - 'fetched <' => date('Y-m-d H:i:s', time() - $task['timeout']), | ||
| 48 | - 'fetched' => null | ||
| 51 | + 'AND' => array( | ||
| 52 | + array( | ||
| 53 | + 'OR' => array( | ||
| 54 | + 'notbefore <' => date('Y-m-d H:i:s'), | ||
| 55 | + 'notbefore' => null | ||
| 56 | + ) | ||
| 57 | + ), | ||
| 58 | + array( | ||
| 59 | + 'OR' => array( | ||
| 60 | + 'fetched <' => date('Y-m-d H:i:s', time() - $task['timeout']), | ||
| 61 | + 'fetched' => null | ||
| 62 | + ) | ||
| 63 | + ) | ||
| 49 | 64 | ), | |
| 50 | 65 | 'failed <' => ($task['retries'] + 1) | |
| 51 | 66 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ public function start() { | |||
| 44 | 44 | /** | |
| 45 | 45 | * Basic Instance test | |
| 46 | 46 | */ | |
| 47 | - public function testCountryInstance() { | ||
| 47 | + public function testQueueInstance() { | ||
| 48 | 48 | $this->assertTrue(is_a($this->QueuedTask, 'TestQueuedTask')); | |
| 49 | 49 | } | |
| 50 | 50 | ||
@@ -178,5 +178,16 @@ public function testSequence() { | |||
| 178 | 178 | $this->assertEqual(9 - $num, $this->QueuedTask->getLength()); | |
| 179 | 179 | } | |
| 180 | 180 | } | |
| 181 | + | ||
| 182 | + public function testNotBefore() { | ||
| 183 | + $this->assertTrue($this->QueuedTask->createJob('task1', null, '+ 1 Min')); | ||
| 184 | + $this->assertTrue($this->QueuedTask->createJob('task1', null, '+ 1 Day')); | ||
| 185 | + $this->assertTrue($this->QueuedTask->createJob('task1', null, '2009-07-01 12:00:00')); | ||
| 186 | + $data = $this->QueuedTask->find('all'); | ||
| 187 | + $this->assertEqual($data[0]['TestQueuedTask']['notbefore'], date('Y-m-d H:i:s', strtotime('+ 1 Min'))); | ||
| 188 | + $this->assertEqual($data[1]['TestQueuedTask']['notbefore'], date('Y-m-d H:i:s', strtotime('+ 1 Day'))); | ||
| 189 | + $this->assertEqual($data[2]['TestQueuedTask']['notbefore'], '2009-07-01 12:00:00'); | ||
| 190 | + | ||
| 191 | + } | ||
| 181 | 192 | } | |
| 182 | 193 | ?> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,11 @@ class QueuedTaskFixture extends CakeTestFixture { | |||
| 33 | 33 | 'type' => 'datetime', | |
| 34 | 34 | 'null' => false | |
| 35 | 35 | ), | |
| 36 | + 'notbefore' => array( | ||
| 37 | + 'type' => 'datetime', | ||
| 38 | + 'null' => false, | ||
| 39 | + 'default' => NULL | ||
| 40 | + ), | ||
| 36 | 41 | 'fetched' => array( | |
| 37 | 42 | 'type' => 'datetime', | |
| 38 | 43 | 'null' => true, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments