예제 #1
0
 function it_on_passes_job_arguments_to_target_class_correctly(JobInstanceFactoryInterface $jobInstanceFactory, JobInterface $job, PerformantJobInterface $targetClass)
 {
     $args = array(1, array('foo' => 'test'), 'key' => 'baz');
     $job->getOriginQueue()->willReturn();
     $job->getId()->willReturn();
     $job->getArguments()->willReturn($args);
     $jobInstanceFactory->createPerformantJob($job)->shouldBeCalled()->willReturn($targetClass);
     $targetClass->perform($args)->shouldBeCalled(1);
     $this->perform($job);
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function save(JobInterface $job, \Exception $exception, WorkerInterface $worker)
 {
     $queue = $job instanceof OriginQueueAwareInterface ? $job->getOriginQueue() : null;
     $this->redis->rpush('failed', json_encode(array('failed_at' => date('c'), 'payload' => $job, 'exception' => get_class($exception), 'error' => $exception->getMessage(), 'backtrace' => explode("\n", $exception->getTraceAsString()), 'worker' => $worker->getId(), 'queue' => $queue instanceof QueueInterface ? $queue->getName() : null)));
 }
예제 #3
0
 /**
  * Process a single job
  *
  * @throws InvalidJobException if the given job cannot actually be asked to perform.
  *
  * @param JobInterface $job The job to be processed.
  * @return bool If job performed or not.
  */
 public function perform(JobInterface $job)
 {
     $status = sprintf('Performing job %s:%s', $job->getOriginQueue(), $job->getId());
     $this->getProcess()->setTitle($status);
     $this->getLogger()->info($status);
     if ($job instanceof TrackableJobInterface) {
         $job->setState(JobInterface::STATE_PERFORMING);
     }
     try {
         $jobInstance = $this->jobInstanceFactory->createPerformantJob($job);
         if (false === $jobInstance instanceof PerformantJobInterface) {
             throw new InvalidJobException('Job ' . $job->getId() . ' "' . get_class($jobInstance) . '" needs to implement Resque\\JobInterface');
         }
         $this->eventDispatcher->dispatch(ResqueJobEvents::BEFORE_PERFORM, new JobInstanceEvent($this, $job, $jobInstance));
         $jobInstance->perform($job->getArguments());
     } catch (\Exception $exception) {
         $this->handleFailedJob($job, $exception);
         return false;
     }
     if ($job instanceof TrackableJobInterface) {
         $job->setState(JobInterface::STATE_COMPLETE);
     }
     $this->getLogger()->notice('{job} has successfully processed', array('job' => $job));
     $this->eventDispatcher->dispatch(ResqueJobEvents::PERFORMED, new WorkerJobEvent($this, $job));
     return true;
 }