Пример #1
0
 /**
  * getInstance
  *
  * @return null|object
  *
  * @throws Resque_Exception
  */
 public function getInstance()
 {
     if (!is_null($this->instance)) {
         return $this->instance;
     }
     if (class_exists('Resque_Job_Creator')) {
         $this->instance = \Resque_Job_Creator::createJob($this->payload['class'], $this->getArguments());
     } else {
         try {
             $this->instance = $this->getServiceLocator()->get($this->payload['class']);
             $this->instance->job = $this;
             $this->instance->args = $this->getArguments();
             $this->instance->queue = $this->queue;
             if (!method_exists($this->instance, 'perform')) {
                 throw new Resque_Exception('Job class ' . $this->payload['class'] . ' does not contain a perform method.');
             }
         } catch (Exception $e) {
             throw new Resque_Exception($e->getMessage());
         }
     }
     return $this->instance;
 }
Пример #2
0
 /**
  * Get the instantiated object for this job that will be performing work.
  *
  * @return object Instance of the object that this job belongs to.
  */
 public function getInstance()
 {
     if (!is_null($this->instance)) {
         return $this->instance;
     }
     if (class_exists('Resque_Job_Creator')) {
         $this->instance = Resque_Job_Creator::createJob($this->payload['class'], $this->getArguments());
     } else {
         if (!class_exists($this->payload['class'])) {
             throw new \Resque_Exception('Could not find job class ' . $this->payload['class'] . '.');
         }
         if (!method_exists($this->payload['class'], 'perform')) {
             throw new \Resque_Exception('Job class ' . $this->payload['class'] . ' does not contain a perform method.');
         }
         $this->instance = new $this->payload['class']();
     }
     $this->instance->job = $this;
     $this->instance->args = $this->getArguments();
     $this->instance->queue = $this->queue;
     return $this->instance;
 }
Пример #3
0
 /**
  * Test job creation from a valid shell class, but without the expected method
  *
  * @expectedException Resque_Exception
  */
 public function testJobWithErrorOnInexistingFunction()
 {
     Resque_Job_Creator::createJob('JobClassOneShell', ['funcThree']);
 }