/**
  * Tries to (re)start a worker in a new process (EXPERIMENTAL!).
  *
  * @param  string  $id        daemon id
  * @param  string  $queueName the name of the queue to work on
  * @param  integer $timeout   time a queue waits for a job in seconds
  */
 public function daemonCommand($id, $queueName, $timeout = 1)
 {
     $this->outputLine('<bg=yellow;options=bold>THIS IS AN EXPERIMENTAL FEATURE!</>');
     // Check if daemon is already running.
     $status = $this->registry->get('daemon:' . $id);
     if (is_array($status) && isset($status['pid'])) {
         if ($this->processExist($status['pid'])) {
             $this->outputFormatted('Daemon "%s" is already running in process "%s".', [$id, $status['pid']]);
             return;
         }
     }
     // // Path to dispatcher.
     $cliDispatchPath = PATH_site . 'typo3/cli_dispatch.phpsh';
     // // Test if a process can be started and the system gets the right pid.
     $command = 'exec php ' . $cliDispatchPath . ' extbase job:sleep --id="' . $id . '"';
     $test = $this->processOpen($command);
     if (empty($test['pid']) || $test['pid'] == getmypid()) {
         throw new \Exception("Method getmypid fails", 1458897118);
     }
     $i = 0;
     while ($this->registry->get('daemon:' . $id) != $test['pid']) {
         if (++$i > 10) {
             throw new \Exception("Failed to verify the pid", 1458894146);
         }
         sleep(1);
     }
     if (!$this->processExist($test['pid'])) {
         throw new \Exception("Failed to verify that the test process is running", 1458896762);
     }
     // Open daemon process
     $command = 'exec php ' . $cliDispatchPath . ' extbase job:work --queue-name="' . $queueName . '" --timeout="' . $timeout . '" --limit="' . Worker::LIMIT_INFINITE . '"';
     if ($sleep !== null) {
         $command .= ' --sleep="' . $sleep . '"';
     }
     if ($memoryLimit !== null) {
         $command .= ' --memory-limit="' . $memoryLimit . '"';
     }
     $status = $this->processOpen($command);
     $this->registry->set('daemon:' . $id, $status);
     $this->outputFormatted('Daemon "%s" started in a new process "%s".', [$id, $status['pid']]);
 }
Beispiel #2
0
 /**
  * Returns true if kill signal has been broadcasted.
  *
  * @param  mixed $lastRestart
  * @return boolean
  */
 protected function shouldRestart($lastRestart)
 {
     return $this->registry->get(Registry::DAEMON_KILL_KEY) !== $lastRestart;
 }