Completed
Push — master ( d19f31...6d358f )
by Matthew
02:58
created

CleanUpWorkersCommand::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 3
eloc 8
nc 2
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Matthew
5
 * Date: 25/06/2014
6
 * Time: 9:30 AM
7
 */
8
9
namespace Mpclarkson\ResqueBundle\Command;
10
11
use Mpclarkson\ResqueBundle\Resque;
12
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
class CleanUpWorkersCommand extends ContainerAwareCommand
17
{
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('resque:cleanup:workers')
22
            ->setDescription('Unregisters all workers in Redis. Workers may need to be restarted.');
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $resque = $this->getContainer()->get('resque');
28
29
        if ($resque instanceof Resque) {
30
            $workers = $resque->getWorkers();
31
32
            foreach ($workers as $worker) {
33
                $output->writeln(sprintf('Unregistered Worker: %s', $worker->getId()));
34
                $worker->getWorker()->unregisterWorker();
35
            }
36
        }
37
38
        $output->writeln('*** Finished ***');
39
    }
40
}
41