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); }
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); }
/** * {@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; }
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); }
/** * {@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))); }
/** * 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)); }
/** * Get redis key * * @param JobInterface $job * @return string */ protected function getRedisKey(JobInterface $job) { return 'job:' . $job->getId() . ':status'; }
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); }
/** * {@inheritDoc} */ public function enqueue(QueueInterface $queue, JobInterface $job) { $result = $this->redis->rpush($this->getRedisKey($queue), $job->encode()); return $result === 1; }
/** * {@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; }