CleanUpWorkersCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 5
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A execute() 0 13 3
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