protected function execute(InputInterface $input, OutputInterface $output) { $id = $input->getArgument('id'); // Do a cleanup $worker = new Resque\Worker('*'); $worker->cleanup(); if ($id) { if (false === ($worker = Resque\Worker::hostWorker($id))) { $this->log('There is no worker with id "' . $id . '".', Resque\Logger::ERROR); return; } $workers = array($worker); } else { $workers = Resque\Worker::hostWorkers(); } if (!count($workers)) { $this->log('<warn>There are no workers on this host</warn>'); } foreach ($workers as $worker) { if (posix_kill($worker->getPid(), SIGTERM)) { $child = pcntl_fork(); // Failed if ($child == -1) { $this->log('Unable to fork, worker ' . $worker . ' has been stopped.', Resque\Logger::CRITICAL); // Parent } elseif ($child > 0) { $this->log('Worker <pop>' . $worker . '</pop> restarted.'); continue; // Child } else { $new_worker = new Resque\Worker($worker->getQueues(), $worker->getBlocking()); $new_worker->setInterval($worker->getInterval()); $new_worker->setTimeout($worker->getTimeout()); $new_worker->setMemoryLimit($worker->getMemoryLimit()); $new_worker->setLogger($this->logger); $new_worker->work(); $this->log('Worker <pop>' . $worker . '</pop> restarted as <pop>' . $new_worker . '</pop>.'); } } else { $this->log('Worker <pop>' . $worker . '</pop> <error>could not send TERM signal.</error>'); } } exit(0); }
protected function execute(InputInterface $input, OutputInterface $output) { $queue = $this->getConfig('queue'); $blocking = filter_var($this->getConfig('blocking'), FILTER_VALIDATE_BOOLEAN); // Create worker instance $worker = new Resque\Worker($queue, $blocking); $worker->setLogger($this->logger); if ($pidFile = $this->getConfig('pid')) { $worker->setPidFile($pidFile); } if ($interval = $this->getConfig('interval')) { $worker->setInterval($interval); } if ($timeout = $this->getConfig('timeout')) { $worker->setTimeout($timeout); } // The memory limit is the amount of memory we will allow the script to occupy // before killing it and letting a process manager restart it for us, which // is to protect us against any memory leaks that will be in the scripts. if ($memory = $this->getConfig('memory')) { $worker->setMemoryLimit($memory); } $worker->work(); }