protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('all')) {
$workers = \Resque_Worker::all();
} else {
$worker = \Resque_Worker::find($input->getArgument('id'));
if (!$worker) {
$availableWorkers = \Resque_Worker::all();
if (!empty($availableWorkers)) {
throw new \RuntimeException('A running worker must be specified');
}
}
$workers = $worker ? array($worker) : array();
}
if (count($workers) <= 0) {
$output->writeln(array('No workers running', ''));
return;
}
$signal = $input->getOption('force') ? SIGTERM : SIGQUIT;
foreach ($workers as $worker) {
$output->writeln(sprintf('%s %s...', $signal === SIGTERM ? 'Force stopping' : 'Stopping', $worker));
list(, $pid) = explode(':', (string) $worker);
posix_kill($pid, $signal);
}
$output->writeln('');
}