Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only kill the workers running on the current machine (branch 1.1.8) #70

Merged
merged 1 commit into from
Nov 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Command/StopWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$resque = $this->getContainer()->get('bcc_resque.resque');

if ($input->getOption('all')) {
$workers = $resque->getWorkers();
$workers = $resque->getWorkers(true);
if (empty($workers)) {
$output->writeln('<comment>You don\'t have any workers on this machine.</comment>');
}
} else {
$worker = $resque->getWorker($input->getArgument('id'));

Expand Down
18 changes: 16 additions & 2 deletions Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,25 @@ public function getQueue($queue)
return new Queue($queue);
}

public function getWorkers()
public function getWorkers($local = false)
{
$workers = \Resque_Worker::all();

if ($local) {
$hostname = php_uname('n');

if(function_exists('gethostname')) {
$hostname = gethostname();
}

$workers = \array_filter($workers, function ($worker) use ($hostname) {
return strpos((string) $worker, $hostname . ':') === 0;
});
}

return \array_map(function ($worker) {
return new Worker($worker);
}, \Resque_Worker::all());
}, $workers);
}

public function getWorker($id)
Expand Down