/** * Handles job get report event by fetching messages from the log table * * @param Event $event * @return \SporkTools\Core\Job\Report */ public function report(Event $event) { $job = $event->getTarget(); $serviceManager = $job->getServiceManager(); $this->initialize($serviceManager); $report = new Report(); $runId = $this->fetchLastBatchId($job); $select = new Select($this->table); $select->columns(array('message' => $this->columnMap['message'], 'type' => $this->columnMap['priority'], 'datetime' => $this->columnMap['timestamp']))->where->like($this->columnMap['message'], "% [{$runId}]"); $results = $this->db->query($select->getSqlString($this->db->getPlatform()), Adapter::QUERY_MODE_EXECUTE); foreach ($results as $row) { $type = isset($this->typeMap[$row->type]) ? $this->typeMap[$row->type] : $row->type; $report->addMessage(new Message($row->message, $type, $row->datetime)); } return $report; }
public function init(Event $event) { if (null === $this->log) { throw new \Exception('Log not set'); } if (!$this->log instanceof LoggerInterface) { $serviceManager = $event->getTarget()->getServiceManager(); if (null === $serviceManager) { throw new \Exception('Log could not be initialized. Service Manager not available.'); } if ($serviceManager->has($this->log)) { $this->log = $serviceManager->get($this->log); if (!$this->log instanceof LoggerInterface) { throw new \Exception('Log must implement \\Zend\\Logger\\LoggerInterface'); } } else { throw new \Exception("Log '{$this->log}' not found in service manager"); } } $this->postfix = ' [' . uniqid() . ']'; }
/** * Injects message plugin and database adapter when job is run * * @param Event $event */ public function initialize(Event $event) { $this->message = $event->getTarget()->getPlugin('SporkTools\\Core\\Job\\Plugin\\Message'); parent::initialize($event); }
public function initialize(Event $event) { $this->eventManager = $event->getTarget()->getEventManager(); }
public function taskFooter(Event $event) { $task = $event->getTarget(); $task->info("Completed task {$task->getName()} {$this->elapsed()}"); }
public function executeTask(Event $event) { $task = $event->getTarget(); return $task->run($event); }
/** * Injects message plugin and database adapter when job is run * * @param Event $event */ public function initialize(Event $event) { if (!$this->db instanceof Adapter) { $this->db = $event->getTarget()->getServiceManager()->get($this->db); } }
public function injectPlugin(Event $event) { $event->getTarget()->addPlugin($this); }
protected function initialize(Event $event) { if (!$this->db instanceof Adapter && null !== $this->db) { $serviceManager = $event->getTarget()->getServiceManager(); $this->db = $serviceManager->get($this->db); } }
public function storeSchedule(Event $event) { $job = $event->getTarget(); $this->initialize($job->getServiceManager()); $schedule = $event->getParam('schedule'); $this->storeData($job, 'schedule', $schedule); }