|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of php-task library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) php-task |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Task\TaskBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Task\Handler\TaskHandlerFactoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Run pending tasks. |
|
22
|
|
|
*/ |
|
23
|
|
|
class RunHandlerCommand extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var TaskHandlerFactoryInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $handlerFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string $name |
|
32
|
|
|
* @param TaskHandlerFactoryInterface $handlerFactory |
|
33
|
|
|
*/ |
|
34
|
12 |
|
public function __construct($name, TaskHandlerFactoryInterface $handlerFactory) |
|
35
|
|
|
{ |
|
36
|
12 |
|
parent::__construct($name); |
|
37
|
|
|
|
|
38
|
12 |
|
$this->handlerFactory = $handlerFactory; |
|
39
|
12 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
12 |
|
protected function configure() |
|
45
|
|
|
{ |
|
46
|
12 |
|
$this->setDescription('Run pending tasks') |
|
47
|
12 |
|
->addArgument('handlerClass', InputArgument::REQUIRED) |
|
48
|
12 |
|
->addArgument('workload', InputArgument::OPTIONAL); |
|
49
|
12 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
3 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
55
|
|
|
{ |
|
56
|
3 |
|
$handlerClass = $input->getArgument('handlerClass'); |
|
57
|
3 |
|
$workload = $input->getArgument('workload'); |
|
58
|
|
|
|
|
59
|
3 |
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
|
60
|
2 |
|
$output->writeln(sprintf('Run command "%s" with workload "%s"', $handlerClass, $workload)); |
|
61
|
2 |
|
} |
|
62
|
|
|
|
|
63
|
3 |
|
$result = $this->handlerFactory->create($handlerClass)->handle($workload); |
|
64
|
|
|
|
|
65
|
3 |
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
|
66
|
2 |
|
$output->writeln(sprintf('Result: %s', json_encode($result))); |
|
67
|
2 |
|
} |
|
68
|
3 |
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|