public function testMonitoringEvent() { $mock_results = $this->getMock('LaterJob\\Model\\Monitor\\Stats'); $event = new MonitoringEvent($mock_results); $event->setResult(false); $this->assertEquals($mock_results, $event->getStats()); $this->assertEquals(false, $event->getResult()); }
/** * Log events that occur from queue * * @access public * @param MonitoringEvent $event */ public function logMonitorRunEvent(MonitoringEvent $event) { $this->log->info('MonitoringEvent:: Monitor running monitor for date', array('date' => $event->getStats()->getMonitorDate())); }
/** * Handles the event MonitoringEventsMap::MONITOR_COMMIT * * @access public * @return void * @param MonitoringEvent $event */ public function onMonitorCommit(MonitoringEvent $event) { try { $stats = $event->getStats(); # save the results into db $success = $this->gateway->updateQuery()->start()->addColumn('worker_max_time', $stats->getWorkerMaxTime())->addColumn('worker_min_time', $stats->getWorkerMinTime())->addColumn('worker_mean_time', $stats->getWorkerMeanTime())->addColumn('worker_mean_throughput', $stats->getWorkerMeanThroughput())->addColumn('worker_max_throughput', $stats->getWorkerMaxThroughput())->addColumn('worker_mean_utilization', $stats->getWorkerMeanUtilization())->addColumn('queue_no_waiting_jobs', $stats->getQueueJobsAdded())->addColumn('queue_no_failed_jobs', $stats->getQueueJobsFailed())->addColumn('queue_no_error_jobs', $stats->getQueueJobsError())->addColumn('queue_no_completed_jobs', $stats->getQueueJobsCompleted())->addColumn('queue_no_processing_jobs', $stats->getQueueJobsProcessing())->addColumn('queue_mean_service_time', $stats->getJobMeanServiceTime())->addColumn('queue_min_service_time', $stats->getJobMinServiceTime())->addColumn('queue_max_service_time', $stats->getJobMaxServiceTime())->addColumn('monitor_complete', true)->where()->filterByMonitor($event->getStats()->getMonitorId())->end()->update(); if ($success === true) { # completed successfuly $event->setResult(true); } } catch (DBALGatewayException $e) { $event->setResult(false); throw new LaterJobException($e->getMessage(), 0, $e); } return $event; }
/** * Log events that occur from queue * * @access public * @param MonitoringEvent $event */ public function logMonitorRunEvent(MonitoringEvent $event) { $this->output->writeln('MonitoringEvent:: Monitor running monitor for date ' . json_encode(array('date' => $event->getStats()->getMonitorDate()))); }
/** * @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); }