1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Task\TaskBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Task\SchedulerInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Schedule task. |
14
|
|
|
* |
15
|
|
|
* @author @wachterjohannes <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class ScheduleTaskCommand extends Command |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var SchedulerInterface |
21
|
|
|
*/ |
22
|
|
|
private $scheduler; |
23
|
18 |
|
|
24
|
|
|
public function __construct($name, SchedulerInterface $scheduler) |
25
|
18 |
|
{ |
26
|
|
|
parent::__construct($name); |
27
|
18 |
|
|
28
|
18 |
|
$this->scheduler = $scheduler; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
18 |
|
*/ |
34
|
|
|
protected function configure() |
35
|
12 |
|
{ |
36
|
18 |
|
$this |
37
|
18 |
|
->setDescription('Run pending tasks') |
38
|
18 |
|
->addArgument('handler', InputArgument::REQUIRED) |
39
|
18 |
|
->addArgument('workload', InputArgument::OPTIONAL) |
40
|
|
|
->addOption('cron-expression', 'c', InputOption::VALUE_REQUIRED) |
41
|
|
|
->addOption('end-date', 'e', InputOption::VALUE_REQUIRED) |
42
|
|
|
->addOption('key', 'e', InputOption::VALUE_REQUIRED); |
43
|
|
|
} |
44
|
12 |
|
|
45
|
|
|
/** |
46
|
12 |
|
* {@inheritdoc} |
47
|
12 |
|
*/ |
48
|
12 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
49
|
12 |
|
{ |
50
|
|
|
$handler = $input->getArgument('handler'); |
51
|
|
|
$workload = $input->getArgument('workload'); |
52
|
|
|
$cronExpression = $input->getOption('cron-expression'); |
53
|
|
|
$endDate = $input->getOption('end-date'); |
54
|
|
|
$key = $input->getOption('key'); |
55
|
|
|
|
56
|
|
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
57
|
|
|
$output->writeln(sprintf('Schedule task "%s" with workload "%s"', $handler, $workload)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$taskBuilder = $this->scheduler->createTask($input->getArgument('handler'), $input->getArgument('workload')); |
61
|
|
|
|
62
|
|
|
if ($cronExpression !== null) { |
63
|
|
|
$taskBuilder->cron($cronExpression, new \DateTime(), new \DateTime($endDate)); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($key !== null) { |
67
|
|
|
$taskBuilder->setKey($key); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$taskBuilder->schedule(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.