/** * {@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_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 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; }