Skip to content

Commit

Permalink
Merge pull request #70 from lightglitch/fix_63_on_stable
Browse files Browse the repository at this point in the history
Only kill the workers running on the current machine (branch 1.1.8)
  • Loading branch information
ulrik nielsen committed Nov 27, 2013
2 parents 594b9d5 + 34bb4d8 commit a56f030
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit a56f030

Please sign in to comment.