Esempio n. 1
0
 public function __construct($configPath, $troubleHandler = null)
 {
     if (!is_string($configPath)) {
         throw new \InvalidArgumentException('Process constructor arguments type error');
     }
     $this->manager = $manager = new StateManager($configPath);
     $this->logger = new Logger($manager->getLogFile());
     if (is_null($troubleHandler)) {
         $this->troubleHandler = new DefaultTrobuleHandler($this->logger);
     } else {
         if ($troubleHandler instanceof TrobuleHandler) {
             $this->troubleHandler = $troubleHandler;
         } else {
             throw new \InvalidArgumentException('Process constructor arguments type error');
         }
     }
     register_shutdown_function(function () {
         $this->troubleHandler->shutdown();
     });
     $jobCount = $manager->getJobCount();
     for ($jid = 0; $jid < $jobCount; $jid++) {
         $classname = $manager->getJobClass($jid);
         if (is_null($classname)) {
             // CallbackJob is default Job, dont need to require
             $this->jobs[$jid] = new CallbackJob($jid);
         } else {
             $classname .= 'Job';
             $this->jobs[$jid] = new $classname($jid);
         }
     }
 }
 public function testGetGlobals()
 {
     $this->reset();
     $obj = new StateManager(__DIR__ . '/testbench/phpprog.json');
     $result = $obj->getGlobals();
     $this->assertEquals($result['idle'], array(true, true));
     $this->assertNull($result['vars']['foo']);
 }
Esempio n. 3
0
 public function __construct($jid)
 {
     if (!is_int($jid)) {
         throw new \InvalidArgumentException('Job constructor arguments type error');
     }
     $this->jid = $jid;
     $this->manager = $manager = new StateManager();
     $this->period = $manager->getJobPeriod($jid);
     $this->state = $state = $manager->getJobState($jid);
     StateManager::completeKeys($state, static::$vars);
     $this->lastRun = $state['last_run'];
 }