/** * 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(); }
public function testQueueConfigParse() { $config = new WorkerConfig(); $data = array('worker' => array('jobs_process' => 4, 'mean_runtime' => 60 * 60 * 1, 'cron_script' => '* * * * *', 'job_lock_timeout' => 60 * 60 * 4, 'worker_name' => 'bobemail')); $config->parse($data); $this->assertEquals($data['worker']['jobs_process'], $config->getJobsToProcess()); $this->assertEquals($data['worker']['mean_runtime'], $config->getMeanRuntime()); $this->assertEquals($data['worker']['cron_script'], $config->getCronDefinition()); $this->assertEquals($data['worker']['job_lock_timeout'], $config->getJobLockoutTime()); $this->assertEquals($data['worker']['worker_name'], $config->getWorkerName()); }
/** * 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; }