Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function setOwner(\Omeka\Entity\User $owner = NULL)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setOwner', array($owner));
     return parent::setOwner($owner);
 }