コード例 #1
0
 public function setUp()
 {
     parent::setUp();
     $config = Zend_Registry::get('Zend_Config');
     $this->__configBackup = $config;
     $config->merge(new Zend_Config(array('runjobs' => array('asynchronous' => true))));
     $this->assertEquals(0, Opus_Job::getCount(Opus_Job::STATE_FAILED), 'test data changed.');
     for ($i = 0; $i < 10; $i++) {
         $job = new Opus_Job();
         $job->setLabel('testjob' . ($i < 5 ? 1 : 2));
         $job->setData(array('documentId' => $i, 'task' => 'get-me-a-coffee'));
         $job->setState(Opus_Job::STATE_FAILED);
         $this->jobIds[] = $job->store();
     }
 }
コード例 #2
0
ファイル: Runner.php プロジェクト: alexukua/opus4
 /**
  * Execute a job and remove it from the jobs table on success.
  *
  * @param Opus_Job $job Job description model.
  * @return boolean Returns true if a job is consumend false if not
  */
 protected function consume(Opus_Job $job)
 {
     $label = $job->getLabel();
     if ($job->getState() !== null) {
         return false;
     }
     if (array_key_exists($label, $this->_workers)) {
         $worker = $this->_workers[$label];
         if (null !== $this->_logger) {
             $this->_logger->info('Processing ' . $label);
         }
         $job->setState(Opus_Job::STATE_PROCESSING);
         $job->store();
         try {
             $worker->setLogger($this->_logger);
             $worker->work($job);
             $job->delete();
             sleep($this->_delay);
         } catch (Exception $ex) {
             if (null !== $this->_logger) {
                 $msg = get_class($worker) . ': ' . $ex->getMessage();
                 $this->_logger->err($msg);
             }
             $job->setErrors(json_encode(array('exception' => get_class($ex), 'message' => $ex->getMessage(), 'trace' => $ex->getTraceAsString())));
             $job->setState(Opus_Job::STATE_FAILED);
             $job->store();
             return false;
         }
         return true;
     }
     return false;
 }