예제 #1
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();
 }
예제 #2
0
 public function testDemolish()
 {
     $entity = new Stats();
     $monitor_id = 1;
     $monitor_date = new DateTime();
     $worker_max_runtime = 60 * 5;
     $worker_min_runtime = 60 * 2;
     $worker_mean_runtime = 60 * 3;
     $worker_mean_throughput = 100;
     $worker_max_throughput = 100;
     $worker_mean_utilization = 50;
     $monitor_complete = false;
     $queue_no_waiting_jobs = 100;
     $queue_no_completed_jobs = 600;
     $queue_no_error_jobs = 500;
     $queue_no_failed_jobs = 400;
     $queue_no_processing_jobs = 300;
     $queue_max_service_time = 350;
     $queue_min_service_time = 375;
     $queue_mean_service_time = 677;
     $entity->setMonitorId($monitor_id);
     $entity->setMonitorDate($monitor_date);
     $entity->setWorkerMaxTime($worker_max_runtime);
     $entity->setWorkerMinTime($worker_min_runtime);
     $entity->setWorkerMeanTime($worker_mean_runtime);
     $entity->setWorkerMeanThroughput($worker_mean_throughput);
     $entity->setWorkerMaxThroughput($worker_max_throughput);
     $entity->setWorkerMeanUtilization($worker_mean_utilization);
     $entity->setComplete($monitor_complete);
     $entity->setQueueJobsAdded($queue_no_waiting_jobs);
     $entity->setQueueJobsCompleted($queue_no_completed_jobs);
     $entity->setQueueJobsError($queue_no_error_jobs);
     $entity->setQueueJobsFailed($queue_no_failed_jobs);
     $entity->setQueueJobsProcessing($queue_no_processing_jobs);
     $entity->setJobMaxServiceTime($queue_max_service_time);
     $entity->setJobMinServiceTime($queue_min_service_time);
     $entity->setJobMeanServiceTime($queue_mean_service_time);
     $builder = new StatsBuilder();
     $data = $builder->demolish($entity);
     $this->assertEquals($data, array('monitor_id' => $monitor_id, 'monitor_complete' => $monitor_complete, 'monitor_dte' => $monitor_date, 'worker_max_time' => $worker_max_runtime, 'worker_min_time' => $worker_min_runtime, 'worker_mean_time' => $worker_mean_runtime, 'worker_max_throughput' => $worker_max_throughput, 'worker_mean_throughput' => $worker_mean_throughput, 'worker_mean_utilization' => $worker_mean_utilization, 'queue_no_waiting_jobs' => $queue_no_waiting_jobs, 'queue_no_completed_jobs' => $queue_no_completed_jobs, 'queue_no_error_jobs' => $queue_no_error_jobs, 'queue_no_failed_jobs' => $queue_no_failed_jobs, 'queue_no_processing_jobs' => $queue_no_processing_jobs, 'queue_max_service_time' => $queue_max_service_time, 'queue_min_service_time' => $queue_min_service_time, 'queue_mean_service_time' => $queue_mean_service_time));
 }
예제 #3
0
 /**
  *  Convert data array into entity
  *
  *  @return mixed
  *  @param array $data
  *  @access public
  */
 public function build($data)
 {
     $obj = new Stats();
     # bind the db id and date the monitor covers
     $obj->setComplete($data['monitor_complete']);
     $obj->setMonitorId($data['monitor_id']);
     if ($data['monitor_dte'] instanceof DateTime) {
         $obj->setMonitorDate($data['monitor_dte']);
     }
     # bind worker run times
     $obj->setWorkerMaxTime($data['worker_max_time']);
     $obj->setWorkerMinTime($data['worker_min_time']);
     $obj->setWorkerMeanTime($data['worker_mean_time']);
     # bind the worker throughput
     $obj->setWorkerMaxThroughput($data['worker_max_throughput']);
     $obj->setWorkerMeanThroughput($data['worker_mean_throughput']);
     $obj->setWorkerMeanUtilization($data['worker_mean_utilization']);
     # bind queue stats
     $obj->setQueueJobsAdded($data['queue_no_waiting_jobs']);
     $obj->setQueueJobsCompleted($data['queue_no_completed_jobs']);
     $obj->setQueueJobsError($data['queue_no_error_jobs']);
     $obj->setQueueJobsFailed($data['queue_no_failed_jobs']);
     $obj->setQueueJobsProcessing($data['queue_no_processing_jobs']);
     # set the job runtimes
     $obj->setJobMaxServiceTime($data['queue_max_service_time']);
     $obj->setJobMinServiceTime($data['queue_min_service_time']);
     $obj->setJobMeanServiceTime($data['queue_mean_service_time']);
     return $obj;
 }
예제 #4
0
 public function toArray(Stats $entity)
 {
     return array('monitorId' => $entity->getMonitorId(), 'monitorComplete' => $entity->getComplete(), 'monitorDate' => $entity->getMonitorDate(), 'workerMaxTime' => $entity->getWorkerMaxTime(), 'workerMinTime' => $entity->getWorkerMinTime(), 'workerMeanTime' => $entity->getWorkerMeanTime(), 'workerMaxThroughput' => $entity->getWorkerMaxThroughput(), 'workerMeanThroughput' => $entity->getWorkerMeanThroughput(), 'workerMeanUtilization' => $entity->getWorkerMeanUtilization(), 'queueNumberAddedJobs' => $entity->getQueueJobsAdded(), 'queueNumberFinishedJobs' => $entity->getQueueJobsCompleted(), 'queueNumberErrorJobs' => $entity->getQueueJobsError(), 'queueNumberFailedJobs' => $entity->getQueueJobsFailed(), 'queueNumberStartedJobs' => $entity->getQueueJobsProcessing(), 'queueMaxServiceTime' => $entity->getJobMaxServiceTime(), 'queueMinServiceTime' => $entity->getJobMinServiceTime(), 'queueMeanServiceTime' => $entity->getJobMeanServiceTime());
 }
 /**
  *  @expectedException LaterJob\Exception
  *  @expectedExceptionMessage SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2012-11-27 13:00:00' for key
  */
 public function testOnMonitorLockAlreadyHasException()
 {
     $date = new DateTime('27-11-2012 13:00:00');
     $transition_gateway = $this->getTransitionTableGateway();
     $monitor_gateway = $this->getMonitorTableGateway();
     $handler = new MonitorSubscriber($monitor_gateway, $transition_gateway);
     # create stats container for results of the monitoring event
     $stats = new Stats();
     $stats->setMonitorDate($date);
     $stats->setWorkerMaxThroughput(50);
     $stats_repeat = new Stats();
     $stats_repeat->setMonitorDate($date);
     $stats_repeat->setWorkerMaxThroughput(50);
     # create event object to pass to handle
     $event = new MonitoringEvent($stats);
     $event->setInterval('+ 5 hours');
     $event_repeat = new MonitoringEvent($stats_repeat);
     $event_repeat->setInterval('+ 5 hours');
     # first call work as normal
     $handler->onMonitorLock($event);
     $this->assertTrue($event->getResult());
     $this->assertEquals(1, $event->getStats()->getMonitorId(1));
     # lock in place should FAIL
     $handler->onMonitorLock($event_repeat);
 }
 public function testOnMonitorCommit()
 {
     $date = new DateTime('10-12-2012 01:00:00');
     $transition_gateway = $this->getTransitionTableGateway();
     $monitor_gateway = $this->getMonitorTableGateway();
     $handler = new MonitorSubscriber($monitor_gateway, $transition_gateway);
     $stats = new Stats();
     $event = new MonitoringEvent($stats);
     $stats->setMonitorDate($date);
     $stats->setWorkerMaxThroughput(50);
     $stats->setMonitorId(1);
     $stats->setQueueJobsAdded(100);
     $stats->setQueueJobsFailed(2);
     $stats->setQueueJobsCompleted(53);
     $stats->setQueueJobsProcessing(56);
     $stats->setQueueJobsError(5);
     $stats->setJobMinServiceTime(8038);
     $stats->setJobMaxServiceTime(10439);
     $stats->setJobMeanServiceTime(9244);
     $stats->setWorkerMaxTime(495);
     $stats->setWorkerMinTime(459);
     $stats->setWorkerMeanTime(482);
     $stats->setWorkerMeanThroughput(27);
     $stats->setWorkerMeanUtilization(0.55);
     $handler->onMonitorCommit($event);
     $resulting_table = $this->getConnection()->createQueryTable("later_job_monitor", "SELECT * FROM later_job_monitor LIMIT 1");
     $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "commit_handler_result.xml")->getTable("later_job_monitor");
     $this->assertEquals(true, $event->getResult());
     $this->assertTablesEqual($expected_table, $resulting_table);
 }
 public function testOnMonitorLock()
 {
     $date = new DateTime('10-12-2012 01:00:00');
     $transition_gateway = $this->getTransitionTableGateway();
     $monitor_gateway = $this->getMonitorTableGateway();
     $handler = new MonitorSubscriber($monitor_gateway, $transition_gateway);
     $stats = new Stats();
     $event = new MonitoringEvent($stats);
     $stats->setMonitorDate($date);
     $handler->onMonitorLock($event);
     $resulting_table = $this->getConnection()->createQueryTable("later_job_monitor", "SELECT * FROM later_job_monitor LIMIT 1");
     $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "lock_handler_result.xml")->getTable("later_job_monitor");
     $this->assertEquals(true, $event->getResult());
     $this->assertTablesEqual($expected_table, $resulting_table);
 }