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\Helper\Table; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Task\Storage\TaskExecutionRepositoryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Run pending tasks. |
23
|
|
|
*/ |
24
|
|
|
class DebugTasksCommand extends Command |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var TaskExecutionRepositoryInterface |
28
|
|
|
*/ |
29
|
|
|
private $taskExecutionRepository; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $name |
33
|
|
|
* @param TaskExecutionRepositoryInterface $storage |
34
|
|
|
*/ |
35
|
12 |
|
public function __construct($name, TaskExecutionRepositoryInterface $storage) |
36
|
|
|
{ |
37
|
12 |
|
parent::__construct($name); |
38
|
|
|
|
39
|
12 |
|
$this->taskExecutionRepository = $storage; |
40
|
12 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
12 |
|
protected function configure() |
46
|
|
|
{ |
47
|
12 |
|
$this->setDescription('Debug tasks') |
48
|
12 |
|
->addOption('page', 'p', InputOption::VALUE_REQUIRED, '', 1) |
49
|
12 |
|
->addOption('page-size', null, InputOption::VALUE_REQUIRED, '', null); |
50
|
12 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
56
|
|
|
{ |
57
|
2 |
|
$page = $input->getOption('page'); |
58
|
2 |
|
$pageSize = $input->getOption('page-size'); |
59
|
|
|
|
60
|
2 |
|
$executions = $this->taskExecutionRepository->findAll($page, $pageSize); |
61
|
|
|
|
62
|
2 |
|
$table = new Table($output); |
63
|
2 |
|
$table->setHeaders(['uuid', 'status', 'handler', 'schedule time', 'end time', 'duration']); |
64
|
|
|
|
65
|
2 |
|
foreach ($executions as $execution) { |
66
|
2 |
|
$table->addRow( |
67
|
|
|
[ |
68
|
2 |
|
$execution->getUuid(), |
69
|
2 |
|
$execution->getStatus(), |
70
|
2 |
|
$execution->getHandlerClass(), |
71
|
2 |
|
$execution->getScheduleTime()->format(\DateTime::RFC3339), |
72
|
2 |
|
!$execution->getEndTime() ? '' : $execution->getEndTime()->format(\DateTime::RFC3339), |
73
|
2 |
|
(round($execution->getDuration(), 6) * 1000000) . 'ms', |
74
|
|
|
] |
75
|
2 |
|
); |
76
|
2 |
|
} |
77
|
|
|
|
78
|
2 |
|
$table->render(); |
79
|
2 |
|
} |
80
|
|
|
} |
81
|
|
|
|