Exemple #1
0
 /**
  * Standard constructor method, the cron job are required.
  * If the job data property is a string, it will be unserialized.
  * @param Enlight_Components_Cron_Job $job
  */
 public function __construct(Enlight_Components_Cron_Job $job)
 {
     $data = $job->getData();
     if (is_string($data)) {
         $data = unserialize($data);
     }
     $this->job = $job;
     parent::__construct($job->getAction(), $data);
 }
 public function testDeleteCronJob()
 {
     $job = new Enlight_Components_Cron_Job($this->jobData);
     $this->assertInstanceOf('Enlight_Components_Cron_Adapter', $this->object->addJob($job));
     $this->job->setId(1);
     $this->jobData['action'] = 'test_action2';
     unset($this->jobData['id']);
     $job2 = new Enlight_Components_Cron_Job($this->jobData);
     $this->assertInstanceOf('Enlight_Components_Cron_Adapter', $this->object->addJob($job2));
     $this->assertArrayCount(2, $f = $this->object->getAllJobs());
     $this->assertInstanceOf('Enlight_Components_Cron_Adapter', $this->object->removeJob($this->job));
     $this->assertNull($this->object->getJobById(1));
     $this->assertInstanceOf('Enlight_Components_Cron_Job', $job3 = $this->object->getJobById(2));
     $this->assertEquals('test_action2', $job3->getAction());
 }
Exemple #3
0
 /**
  * Ends a job by handing it over to
  *
  * @param Enlight_Components_Cron_Job $job
  * @return void
  */
 protected function endJob(Enlight_Components_Cron_Job $job)
 {
     $now = new Zend_Date();
     $now = $now->getTimestamp();
     $interval = $job->getInterval();
     $next = $job->getNext()->getTimestamp();
     do {
         $next += $interval;
     } while ($now >= $next);
     $job->setNext($next);
     $job->setEnd($now);
     $this->adapter->updateJob($job);
 }
Exemple #4
0
 /**
  * Removes an job from the cron tab
  *
  * @param Enlight_Components_Cron_Job $job
  * @return Enlight_Components_Cron_Adapter_DbTable
  */
 public function removeJob(Enlight_Components_Cron_Job $job)
 {
     $where = $this->getAdapter()->quoteInto($this->getAdapter()->quoteIdentifier($this->_primary) . ' = ?', $job->getId());
     $this->delete($where);
     return $this;
 }
Exemple #5
0
 /**
  * Removes an job from the cron tab
  *
  * @param Enlight_Components_Cron_Job $job
  * @return Enlight_Components_Cron_Adapter_DbTable
  */
 public function deleteJob(Enlight_Components_Cron_Job $job)
 {
     $this->delete(array($this->getAdapter()->quoteIdentifier($this->_primary) . ' = ?' => $job->getId()));
     return $this;
 }
Exemple #6
0
 /**
  * @todo Implement testSetActive().
  */
 public function testSetActive()
 {
     $this->assertInstanceOf('Enlight_Components_Cron_Job', $this->job->setActive(false));
     $this->assertFalse($this->job->isActive());
 }
Exemple #7
0
 /**
  * Starts a job by handing it over to
  *
  * @param Enlight_Components_Cron_Job $job
  * @return void|bool
  */
 private function startJob(Enlight_Components_Cron_Job $job)
 {
     $nextRun = $job->getNext();
     // get next Date
     // Turn clock forward
     do {
         $nextRun->addSecond($job->getInterval());
     } while ($nextRun->compare(new Zend_Date()) >= 0);
     $job->setStart(new Zend_Date());
     $job->setEnd(null);
     try {
         $this->_adapter->updateJob($job);
         $job->setNext($nextRun);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function deleteJob(Enlight_Components_Cron_Job $job)
 {
     $this->connection->delete($this->tableName, ['id' => $job->getId()]);
 }