CleanUpWorkersCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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