Beispiel #1
0
 /**
  * @keepalive
  */
 public function startMaintenance()
 {
     $clockwork = new CM_Clockwork_Manager();
     $storage = new CM_Clockwork_Storage_FileSystem('search-maintenance');
     $storage->setServiceManager(CM_Service_Manager::getInstance());
     $clockwork->setStorage($storage);
     $clockwork->registerCallback('search-index-update', '1 minute', array($this, 'update'));
     $clockwork->registerCallback('search-index-optimize', '1 hour', array($this, 'optimize'));
     $clockwork->start();
 }
Beispiel #2
0
 public function testRegisterEvent()
 {
     $manager = new CM_Clockwork_Manager();
     $manager->registerEvent(new CM_Clockwork_Event('foo', '1 second'));
     $manager->registerEvent(new CM_Clockwork_Event('bar', '1 second'));
     try {
         $manager->registerEvent(new CM_Clockwork_Event('foo', '1 second'));
         $this->fail('Registered duplicate event');
     } catch (CM_Exception $ex) {
         $this->assertSame('Duplicate event-name', $ex->getMessage());
     }
 }
Beispiel #3
0
 /**
  * @param string    $dateTimeString
  * @param Closure[] $callbacks
  */
 protected function _registerClockworkCallbacks($dateTimeString, $callbacks)
 {
     foreach ($callbacks as $name => $callback) {
         $transactionName = 'cm ' . static::getPackageName() . ' start: ' . $name;
         $this->_clockworkManager->registerCallback($name, $dateTimeString, function () use($transactionName, $callback) {
             CM_Service_Manager::getInstance()->getNewrelic()->startTransaction($transactionName);
             try {
                 $callback();
             } catch (CM_Exception $e) {
                 CM_Bootloader::getInstance()->getExceptionHandler()->handleException($e);
             }
             CM_Service_Manager::getInstance()->getNewrelic()->endTransaction();
         });
     }
 }
Beispiel #4
0
 /**
  * @param string    $dateTimeString
  * @param Closure[] $callbacks
  */
 protected function _registerClockworkCallbacks($dateTimeString, $callbacks)
 {
     foreach ($callbacks as $name => $callback) {
         $transactionName = 'cm ' . static::getPackageName() . ' start: ' . $name;
         $this->_clockworkManager->registerCallback($name, $dateTimeString, function () use($transactionName, $callback) {
             CM_Service_Manager::getInstance()->getNewrelic()->startTransaction($transactionName);
             try {
                 call_user_func_array($callback, func_get_args());
             } catch (CM_Exception $e) {
                 CM_Service_Manager::getInstance()->getNewrelic()->endTransaction();
                 throw $e;
             }
             CM_Service_Manager::getInstance()->getNewrelic()->endTransaction();
         });
     }
 }
Beispiel #5
0
 public function testStartTerminatable()
 {
     $process = CM_Process::getInstance();
     $forkHandler = $process->fork(function () {
         $clockworkManager = new CM_Clockwork_Manager();
         $clockworkManager->start();
     });
     usleep(1000000 * 0.1);
     $process->listenForChildren();
     $this->assertSame(true, $process->isRunning($forkHandler->getPid()));
     posix_kill($forkHandler->getPid(), SIGTERM);
     usleep(1000000 * 0.1);
     $process->listenForChildren();
     $this->assertSame(false, $process->isRunning($forkHandler->getPid()));
 }