예제 #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_pushes_enqueued_jobs_into_redis(RedisClientInterface $redis, QueueInterface $queue, JobInterface $job)
 {
     $queue->getName()->shouldBeCalled()->willReturn('bar');
     $job->encode()->shouldBeCalled()->willReturn('{"encoded":"job"}');
     $redis->rpush('queue:bar', '{"encoded":"job"}')->shouldBeCalled()->willReturn(1);
     $this->enqueue($queue, $job)->shouldReturn(true);
 }
 /**
  * {@inheritdoc}
  */
 public function createPerformantJob(JobInterface $job)
 {
     $target = $job->getJobClass();
     if ($this->container->has($target)) {
         return $this->container->get($target);
     }
     return parent::createPerformantJob($job);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function createPerformantJob(JobInterface $job)
 {
     $class = $job->getJobClass();
     if (false === class_exists($class)) {
         throw new JobNotFoundException('Could not find job class "' . $class . '"');
     }
     $instance = new $class();
     return $instance;
 }
예제 #5
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);
 }
예제 #6
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)));
 }
예제 #7
0
 /**
  * Handle failed job
  *
  * @param JobInterface $job The job that failed.
  * @param \Exception $exception The reason the job failed.
  */
 protected function handleFailedJob(JobInterface $job, \Exception $exception)
 {
     if ($job instanceof TrackableJobInterface) {
         $job->setState(JobInterface::STATE_FAILED);
     }
     $this->getLogger()->error('Perform failure on {job}, {message}', array('job' => $job, 'message' => $exception->getMessage(), 'exception' => $exception));
     $this->eventDispatcher->dispatch(ResqueJobEvents::FAILED, new JobFailedEvent($job, $exception, $this));
 }
예제 #8
0
 /**
  * Get redis key
  *
  * @param JobInterface $job
  * @return string
  */
 protected function getRedisKey(JobInterface $job)
 {
     return 'job:' . $job->getId() . ':status';
 }
예제 #9
0
 function it_should_throw_on_job_not_found(JobInterface $job)
 {
     $job->getJobClass()->shouldBeCalled()->willReturn('Resque\\Tests\\Jobs\\NonExistent');
     $this->shouldThrow('Resque\\Component\\Job\\Exception\\JobNotFoundException')->duringCreatePerformantJob($job);
 }
예제 #10
0
 /**
  * {@inheritDoc}
  */
 public function enqueue(QueueInterface $queue, JobInterface $job)
 {
     $result = $this->redis->rpush($this->getRedisKey($queue), $job->encode());
     return $result === 1;
 }
예제 #11
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;
 }