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