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
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Mkk\GearmanBundle\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
use Mkk\GearmanBundle\Command\Abstracts\AbstractGearmanCommand; |
19
|
|
|
use Mkk\GearmanBundle\Service\GearmanClient; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Gearman Job List Command class |
23
|
|
|
*/ |
24
|
|
|
class GearmanWorkerListCommand extends AbstractGearmanCommand |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var GearmanClient |
28
|
|
|
* |
29
|
|
|
* Gearman client |
30
|
|
|
*/ |
31
|
|
|
protected $gearmanClient; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Set gearman client |
35
|
|
|
* |
36
|
|
|
* @param GearmanClient $gearmanClient Gearman client |
37
|
|
|
* |
38
|
|
|
* @return GearmanWorkerListCommand self Object |
39
|
|
|
*/ |
40
|
2 |
|
public function setGearmanClient(GearmanClient $gearmanClient) |
41
|
|
|
{ |
42
|
2 |
|
$this->gearmanClient = $gearmanClient; |
43
|
|
|
|
44
|
2 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Console Command configuration |
49
|
|
|
*/ |
50
|
2 |
|
protected function configure() |
51
|
|
|
{ |
52
|
2 |
|
parent::configure(); |
53
|
|
|
|
54
|
|
|
$this |
55
|
2 |
|
->setName('gearman:worker:list') |
56
|
2 |
|
->setDescription('List all Gearman Workers and their Jobs'); |
57
|
2 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Executes the current command. |
61
|
|
|
* |
62
|
|
|
* @param InputInterface $input An InputInterface instance |
63
|
|
|
* @param OutputInterface $output An OutputInterface instance |
64
|
|
|
* |
65
|
|
|
* @return integer 0 if everything went fine, or an error code |
|
|
|
|
66
|
|
|
* |
67
|
|
|
* @throws \LogicException When this abstract class is not implemented |
68
|
|
|
*/ |
69
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
70
|
|
|
{ |
71
|
2 |
|
if ($input->getOption('quiet')) { |
72
|
1 |
|
return; |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
$workers = $this->gearmanClient->getWorkers(); |
76
|
|
|
|
77
|
1 |
|
if (is_array($workers)) { |
78
|
|
|
|
79
|
1 |
|
$it = 1; |
|
|
|
|
80
|
|
|
|
81
|
1 |
|
foreach ($workers as $worker) { |
82
|
|
|
|
83
|
1 |
|
$output->writeln('<comment>@Worker: </comment><info>' . $worker['className'] . '</info>'); |
84
|
1 |
|
$output->writeln('<comment>callablename: </comment><info>' . $worker['callableName'] . '</info>'); |
85
|
1 |
|
$output->writeln('<comment>Jobs:</comment>'); |
86
|
1 |
|
foreach ($worker['jobs'] as $job) { |
87
|
|
|
$output->writeln('<comment> - #' . $it++ . '</comment>'); |
|
|
|
|
88
|
|
|
$output->writeln('<comment> name: ' . $job['methodName'] . '</comment>'); |
89
|
|
|
$output->writeln('<comment> callablename:</comment><info> ' . $job['realCallableNameNoPrefix'] . '</info>'); |
|
|
|
|
90
|
|
|
|
91
|
|
|
if (false === is_null($job['jobPrefix'])) { |
92
|
|
|
|
93
|
1 |
|
$output->writeln('<comment> jobPrefix:</comment><info> ' . $job['jobPrefix'] . '</info>'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
1 |
|
} |
99
|
|
|
} |
|
|
|
|
100
|
|
|
|
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.