Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function updateJob(Enlight_Components_Cron_Job $job)
 {
     $data = [];
     $data['action'] = $job->getAction();
     $data[$this->connection->quoteIdentifier('interval')] = $job->getInterval();
     $data['data'] = serialize($job->getData());
     $data['active'] = $job->getActive() ? '1' : '0';
     $data['next'] = $job->getNext() ? $job->getNext()->toString('YYYY-MM-dd HH:mm:ss') : null;
     $data['start'] = $job->getStart() ? $job->getStart()->toString('YYYY-MM-dd HH:mm:ss') : null;
     $data['end'] = $job->getEnd() ? $job->getEnd()->toString('YYYY-MM-dd HH:mm:ss') : null;
     if (is_null($job->getId())) {
         $this->connection->insert($this->tableName, $data);
     } else {
         $this->connection->update($this->tableName, $data, ['id' => $job->getId()]);
     }
 }
Beispiel #2
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);
 }
Beispiel #3
0
 /**
  * @todo Implement testSetInterval().
  */
 public function testSetInterval()
 {
     $this->assertInstanceOf('Enlight_Components_Cron_Job', $this->job->setInterval('8000'));
     $this->assertEquals(8000, $this->job->getInterval());
 }
Beispiel #4
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;
     }
 }