StopScheduledWorkerCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 0
cbo 4
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A execute() 0 20 2
1
<?php
2
3
namespace Mpclarkson\ResqueBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Class StopScheduledWorkerCommand
11
 * @package Mpclarkson\ResqueBundle\Command
12
 */
13
class StopScheduledWorkerCommand extends ContainerAwareCommand
14
{
15
    /**
16
     *
17
     */
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('resque:scheduledworker-stop')
22
            ->setDescription('Stop a resque scheduled worker');
23
    }
24
25
    /**
26
     * @param InputInterface $input
27
     * @param OutputInterface $output
28
     * @return int
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $pidFile = $this->getContainer()->get('kernel')->getCacheDir() . '/resque_scheduledworker.pid';
33
34
        if (!file_exists($pidFile)) {
35
            $output->writeln('No PID file found');
36
37
            return -1;
38
        }
39
40
        $pid = file_get_contents($pidFile);
41
42
        $output->writeln('Killing process ' . $pid);
43
44
        \posix_kill($pid, SIGKILL);
45
46
        unlink($pidFile);
47
48
        return 0;
49
    }
50
}
51