public function testgetLiternal()
 {
     $config = new WorkerConfig();
     $this->assertEquals('LaterJob\\Config\\WorkerConfig::STATE_START', $config->getLiteral(1));
     $this->assertEquals('LaterJob\\Config\\WorkerConfig::STATE_FINISH', $config->getLiteral(2));
     $this->assertEquals('LaterJob\\Config\\WorkerConfig::STATE_ERROR', $config->getLiteral(3));
 }
Exemple #2
0
 /**
  *  Run the monitor over the given hour.
  *
  *  @access public
  *  @return LaterJob\Model\Monitor\Stats with result and stats data for period
  *  @param DateTime $hour should be the hour to run the monitor over.
  */
 public function monitor(DateTime $hour)
 {
     $stats = new Stats();
     $event = new MonitoringEvent($stats);
     $stats->setMonitorDate($hour);
     $stats->setWorkerMaxThroughput($this->worker_config->getJobsToProcess());
     # lock
     $this->event->dispatch(MonitoringEventsMap::MONITOR_LOCK, $event);
     # gather
     $event->setResult(false);
     $this->event->dispatch(MonitoringEventsMap::MONITOR_RUN, $event);
     # commit
     $event->setResult(false);
     $this->event->dispatch(MonitoringEventsMap::MONITOR_COMMIT, $event);
     return $event->getStats();
 }
Exemple #3
0
 /**
  *  Have the worker receive jobs.
  *
  *  @return LaterJob\Allocator
  *  @access public
  */
 public function receive(DateTime $now)
 {
     $jobs_to_process = $this->definition->getJobsToProcess();
     $lockout_time = $this->definition->getJobLockoutTime();
     $worker_id = $this->getId();
     # add the lockout to the date argument
     $lockout = clone $now;
     $lockout->modify('+' . $lockout_time . ' seconds');
     # call the receive on the allocator to lock a list of jobs
     $this->allocator->receive($jobs_to_process, $worker_id, $lockout, $now);
     # return the allocator so processing script can iterate over
     # the job list
     return $this->allocator;
 }
 public function parseWorkerOptions(array $options, WorkerConfig $worker)
 {
     return $worker->parse($options);
 }