1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gendoria\CommandQueue\Console\Command; |
4
|
|
|
|
5
|
|
|
use Gendoria\CommandQueue\Worker\WorkerRunnerManager; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Description of RunWorkerCommand |
12
|
|
|
* |
13
|
|
|
* @author Tomasz Struczyński <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class ListWorkersCommand extends Command |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Worker runner manager. |
19
|
|
|
* |
20
|
|
|
* @var WorkerRunnerManager |
21
|
|
|
*/ |
22
|
|
|
private $runnerManager; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Set worker runner manager. |
26
|
|
|
* |
27
|
|
|
* @param WorkerRunnerManager $runnerManager Worker runner manager instance. |
28
|
|
|
*/ |
29
|
|
|
public function setRunnerManager(WorkerRunnerManager $runnerManager) |
30
|
|
|
{ |
31
|
|
|
$this->runnerManager = $runnerManager; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this->setName('cmq:worker:list') |
37
|
|
|
->setDescription('List available workers'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
41
|
|
|
{ |
42
|
|
|
if (null === $this->runnerManager) { |
43
|
|
|
$output->writeln("<error>Runner manager not provided to command. Command is not correctly initialized.</error>"); |
44
|
|
|
return 1; |
45
|
|
|
} |
46
|
|
|
$runners = $this->runnerManager->getRunners(); |
47
|
|
|
$runnersFormatted = array_map(array($this, 'formatRunnerName'), $runners); |
48
|
|
|
$output->writeln('Registered workers:'); |
49
|
|
|
$output->writeln($runnersFormatted); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function formatRunnerName($name) |
53
|
|
|
{ |
54
|
|
|
return sprintf(" * <info>%s</info>", $name); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|