Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function start()
 {
     if ($this->started === false) {
         $this->getOutput()->write("[+] Starting worker");
         $this->started = true;
         $this->process->open();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($validator)
 {
     $this->assertHasProcess();
     if ($validator instanceof \Closure) {
         $validator = new ProcessValidator($validator, 'An error occurred.');
     }
     if (!$validator instanceof ProcessValidatorInterface) {
         throw new \InvalidArumentException();
     }
     $this->process->setValidator($validator);
     return $this;
 }
 public function testResolveTimeoutsWithPayloadInCorrectState()
 {
     $timeout = $this->getMockBuilder('\\StateMachine\\PayloadTimeout')->disableOriginalConstructor()->getMock();
     $timeout->expects($this->any())->method('getState')->willReturn('timeout');
     $this->timeoutHandler->expects($this->any())->method('getExpired')->willReturn([$timeout]);
     $this->payload->expects($this->any())->method('getState')->willReturn('timeout');
     $this->payloadHandler->expects($this->any())->method('restore')->willReturn($this->payload);
     $this->adapter->expects($this->any())->method('getProcess')->willReturn($this->process);
     $this->process->expects($this->once())->method('triggerEvent');
     $this->timeoutHandler->expects($this->once())->method('remove');
     $machine = new StateMachine($this->adapter, $this->payloadHandler, $this->timeoutHandler, $this->lockHandler);
     $machine->resolveTimeouts();
 }
Beispiel #4
0
 /**
  * Fork child process
  *
  * @param mixed $arg
  * @final
  */
 private final function Fork($arg)
 {
     $pid = @pcntl_fork();
     if (!$pid) {
         try {
             if ($this->ProcessObject->IsDaemon) {
                 $this->DemonizeProcess();
             }
             $this->ProcessObject->StartThread($arg);
         } catch (\Exception $err) {
             $this->Logger->error($err->getMessage());
         }
         exit;
     } else {
         if ($this->PIDDir) {
             $this->Logger->debug("Touch thread PID file {$pid}");
             touch($this->PIDDir . "/" . $pid);
         }
         $this->Logger->debug("Child with PID# {$pid} successfully forked");
         $this->PIDs[$pid] = array("start_time" => time(), "pid" => $pid);
     }
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function run($size = ProcessInterface::DEFAULT_QUANTITY_PROCESESS)
 {
     return $this->process->size($size)->create($this->each());
 }
Beispiel #6
0
 /**
  * Execute event in set process for set payload
  * If final state has timeout event, store it for further execution
  * Return run history
  *
  * @param ProcessInterface $process
  * @param PayloadInterface $payload
  * @param string           $event
  *
  * @return array
  */
 private function resolveEvent(ProcessInterface $process, PayloadInterface $payload, $event)
 {
     $result = $process->triggerEvent($event, $payload);
     if ($payload->hasChanged() && $process->hasTimeout($payload)) {
         $this->timeoutHandler->store($process->getTimeout($payload, new \DateTime()));
     }
     $this->payloadHandler->store($payload);
     return $result;
 }