/** * @param CM_Clockwork_Event $event * @param DateTime $runtime */ public function setRuntime(CM_Clockwork_Event $event, DateTime $runtime) { if (null === $this->_data) { $this->_data = $this->_load(); } $this->_data[$event->getName()] = clone $runtime; $this->_save($this->_data); }
public function testRun() { $counter = array('foo' => 0, 'bar' => 0); $event = new CM_Clockwork_Event('event', '1 second'); $event->registerCallback(function () use(&$counter) { $counter['foo']++; }); $event->run(); $event->registerCallback(function () use(&$counter) { $counter['bar']++; }); $event->run(); $this->assertSame(array('foo' => 2, 'bar' => 1), $counter); }
public function testGetLastRuntime() { $storage = $this->mockObject('CM_Clockwork_Storage_Abstract', ['foo']); $event1 = new CM_Clockwork_Event('event1', '1 second'); $event2 = new CM_Clockwork_Event('event2', '1 second'); $executionTime1 = new DateTime(); $executionTime2 = new DateTime('1 minute'); $storage->mockMethod('_load')->at(0, function () use($event1, $event2, $executionTime1, $executionTime2) { return [$event1->getName() => $executionTime1, $event2->getName() => $executionTime2]; })->set(function () { throw new CM_Exception_AuthRequired('`_load()` called too often'); }); /** @var CM_Clockwork_Storage_Abstract $storage */ $this->assertEquals($executionTime1, $storage->getLastRuntime($event1)); $this->assertNotSame($executionTime1, $storage->getLastRuntime($event1)); // make sure datetime object is cloned $this->assertEquals($executionTime2, $storage->getLastRuntime($event2)); }
/** * @param CM_Clockwork_Event $event */ protected function _runEvent(CM_Clockwork_Event $event) { $process = $this->_getProcess(); $identifier = $process->fork(function () use($event) { $event->run(); }); $this->_markRunning($event, $identifier); }
/** * @param CM_Clockwork_Event $event */ protected function _markCompleted(CM_Clockwork_Event $event) { $startTime = $this->_eventsRunning[$event->getName()]['startTime']; $this->_storage->setRuntime($event, $startTime); }