예제 #1
0
 function it_when_asked_if_job_is_complete_returns_false_when_it_is_not_complete(RedisClientInterface $redis, JobInterface $job)
 {
     $job->getId()->willReturn('baz');
     $redis->exists('job:baz:status')->shouldBeCalled()->willReturn(true);
     $redis->get('job:baz:status')->shouldBeCalled()->willReturn('{"status": "processing"}');
     $this->isComplete($job)->shouldReturn(false);
 }
예제 #2
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);
 }
예제 #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;
 }
예제 #4
0
 /**
  * Get redis key
  *
  * @param JobInterface $job
  * @return string
  */
 protected function getRedisKey(JobInterface $job)
 {
     return 'job:' . $job->getId() . ':status';
 }
예제 #5
0
파일: Job.php 프로젝트: php-resque/resque
 /**
  * {@inheritdoc}
  */
 public static function matchFilter(JobInterface $job, $filter = array())
 {
     $filters = array('id' => function (JobInterface $job, $filter) {
         if (isset($filter['id'])) {
             return $filter['id'] === $job->getId();
         }
         return null;
     }, 'class' => function (JobInterface $job, $filter) {
         if (isset($filter['class'])) {
             return $filter['class'] === $job->getJobClass();
         }
         return null;
     });
     $results = array();
     foreach ($filters as $filterName => $filterCallback) {
         $result = $filterCallback($job, $filter);
         // Discard null results as that is the callback telling us it's conditional is not set.
         if (null === $result) {
             continue;
         }
         $results[$filterName] = $result;
     }
     return count(array_unique($results)) === 1 && reset($results) === true;
 }