/** * Dispatch a job. * * Composes a Job entity and uses the configured strategy if no strategy is * passed. * * @param string $class * @param mixed $args * @param StrategyInterface $strategy * @return null|Job $job */ public function dispatch($class, $args = null, StrategyInterface $strategy = null) { if (!is_subclass_of($class, 'Omeka\\Job\\JobInterface')) { throw new Exception\InvalidArgumentException(sprintf('The job class "%s" does not implement Omeka\\Job\\JobInterface.', $class)); } $entityManager = $this->getServiceLocator()->get('Omeka\\EntityManager'); $auth = $this->getServiceLocator()->get('Omeka\\AuthenticationService'); $job = new Job(); $job->setStatus(Job::STATUS_STARTING); $job->setClass($class); $job->setArgs($args); $job->setOwner($auth->getIdentity()); $entityManager->persist($job); $entityManager->flush(); if (!$strategy) { $strategy = $this->getDispatchStrategy(); } $this->send($job, $strategy); return $job; }
/** * {@inheritDoc} */ public function setArgs($args) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setArgs', array($args)); return parent::setArgs($args); }