Completed
Push — master ( 0585fd...6ce168 )
by Mickael
03:38
created

GearmanWorkerExecuteCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 0
loc 118
ccs 0
cts 88
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 37 1
B execute() 0 64 7
1
<?php
2
3
/**
4
 * Gearman Bundle for Symfony2 / Symfony3
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * Feel free to edit as you please, and have fun.
10
 *
11
 * @author Marc Morera <[email protected]>
12
 * @author Mickael Perraud <[email protected]>
13
 */
14
15
namespace Mkk\GearmanBundle\Command;
16
17
use Symfony\Component\Console\Helper\QuestionHelper;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
23
use Symfony\Component\Console\Question\ConfirmationQuestion;
24
25
/**
26
 * Gearman Worker Execute Command class
27
 */
28
class GearmanWorkerExecuteCommand extends ContainerAwareCommand
29
{
30
    /**
31
     * Console Command configuration
32
     */
33
    protected function configure()
34
    {
35
        parent::configure();
36
37
        $this
38
            ->setName('gearman:worker:execute')
39
            ->setDescription('Execute one worker with all contained Jobs')
40
            ->addArgument(
41
                'worker',
42
                InputArgument::REQUIRED,
43
                'work to execute'
44
            )
45
            ->addOption(
46
                'no-description',
47
                null,
48
                InputOption::VALUE_NONE,
49
                'Don\'t print worker description'
50
            )
51
            ->addOption(
52
                'iterations',
53
                null,
54
                InputOption::VALUE_OPTIONAL,
55
                'Override configured iterations'
56
            )
57
            ->addOption(
58
                'minimum-execution-time',
59
                null,
60
                InputOption::VALUE_OPTIONAL,
61
                'Override configured minimum execution time'
62
            )
63
            ->addOption(
64
                'timeout',
65
                null,
66
                InputOption::VALUE_OPTIONAL,
67
                'Override configured timeout'
68
            );
69
    }
70
71
    /**
72
     * Executes the current command.
73
     *
74
     * @param InputInterface  $input  An InputInterface instance
75
     * @param OutputInterface $output An OutputInterface instance
76
     *
77
     * @return integer 0 if everything went fine, or an error code
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
78
     *
79
     * @throws \LogicException When this abstract class is not implemented
80
     */
81
    protected function execute(InputInterface $input, OutputInterface $output)
82
    {
83
        /**
84
         * @var QuestionHelper $question
85
         */
86
        $question = $this
87
            ->getHelperSet()
88
            ->get('question');
89
90
        if (
91
            !$input->getOption('no-interaction') &&
92
            !$question->ask(
93
                $input,
94
                $output,
95
                new ConfirmationQuestion('This will execute asked worker with all its jobs?')
96
            )
97
        ) {
98
            return;
99
        }
100
101
        if (!$input->getOption('quiet')) {
102
103
            $output->writeln(sprintf(
104
                '<info>[%s] loading...</info>',
105
                date('Y-m-d H:i:s')
106
            ));
107
        }
108
109
        $worker = $input->getArgument('worker');
110
111
        $workerStructure = $this
112
            ->getContainer()->get('gearman')
113
            ->getWorker($worker);
114
115
        if (
116
            !$input->getOption('no-description') &&
117
            !$input->getOption('quiet')
118
        ) {
119
            $this
120
                ->getContainer()->get('gearman.describer')
121
                ->describeWorker(
122
                    $output,
123
                    $workerStructure,
124
                    true
125
                );
126
        }
127
128
        if (!$input->getOption('quiet')) {
129
130
            $output->writeln(sprintf(
131
                '<info>[%s] loaded. Ctrl+C to break</info>',
132
                date('Y-m-d H:i:s')
133
            ));
134
        }
135
136
        $this
137
            ->getContainer()->get('gearman.execute')
138
            ->setOutput($output)
139
            ->executeWorker($worker, array(
140
                'iterations'             => $input->getOption('iterations'),
141
                'minimum_execution_time' => $input->getOption('minimum-execution-time'),
142
                'timeout'                => $input->getOption('timeout')
143
            ));
144
    }
145
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
146