Beispiel #1
0
 /**
  * Stops this Worker.
  *
  * @param integer $signal [OPTIONAL] Contains the signal in the case of a PCNTL signal.
  */
 public function stop($signal = null)
 {
     if (!$this->running) {
         return;
     }
     if (null !== $signal) {
         $this->getLogger()->info('Stop called because of signal #' . $signal . '. Current state: ' . $this->worker->getState() . '.');
     } else {
         $this->getLogger()->info('Stop called: ' . $this->worker->getState() . '.');
     }
     $this->running = false;
     $this->worker->shutdown();
 }
 /**
  * Sends when the Service is done working, this sends the result to the Worker Handler.
  */
 public function handleResult()
 {
     // No result
     $result = $this->worker->getResult();
     if ($result === null) {
         return;
     }
     // Invalid worker state, wait for a response first.
     if (!$this->isWorkerHandlerReady()) {
         return;
     }
     $this->sendToWorkerHandler(new Protocol\JobResult($this->worker->getRequestId(), $result));
     $this->worker->setState(Worker::RESULT);
 }