Skip to content

Commit 61fd1b7

Browse files
added command and extended storage
1 parent 95af33f commit 61fd1b7

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

src/Command/DebugTasksCommand.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace Task\TaskBundle\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Helper\Table;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use Task\Storage\StorageInterface;
10+
11+
/**
12+
* Run pending tasks.
13+
*
14+
* @author @wachterjohannes <[email protected]>
15+
*/
16+
class DebugTasksCommand extends Command
17+
{
18+
/**
19+
* @var StorageInterface
20+
*/
21+
private $storage;
22+
23+
public function __construct($name, StorageInterface $storage)
24+
{
25+
parent::__construct($name);
26+
27+
$this->storage = $storage;
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
protected function configure()
34+
{
35+
$this->setDescription('Debug tasks')
36+
->addOption('limit', 'l')
37+
->addOption('key');
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
protected function execute(InputInterface $input, OutputInterface $output)
44+
{
45+
$key = $input->getOption('key');
46+
$limit = $input->getOption('limit');
47+
48+
if (null !== $key) {
49+
$tasks = $this->storage->findByKey($key, $limit);
50+
} else {
51+
$tasks = $this->storage->findAll($limit);
52+
}
53+
54+
$table = new Table($output);
55+
$table->setHeaders(array('uuid', 'key', 'task-name', 'execution-date', 'completed', 'start', 'duration'));
56+
57+
foreach ($tasks as $task) {
58+
$start = null;
59+
$duration = null;
60+
if (null !== $task->getLastExecution()) {
61+
$start = $task->getLastExecution()->getFinishedAtAsDateTime()->format(\DateTime::RFC3339);
62+
$duration = $task->getLastExecution()->getExecutionDuration();
63+
}
64+
65+
$table->addRow(
66+
[
67+
$task->getUuid(),
68+
$task->getKey(),
69+
$task->getTaskName(),
70+
$task->getExecutionDate()->format(\DateTime::RFC3339),
71+
$task->isCompleted(),
72+
$start,
73+
$duration,
74+
]
75+
);
76+
}
77+
78+
$table->render();
79+
}
80+
}

src/Storage/DoctrineStorage.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,26 @@ function (TaskEntity $entity) {
7070
/**
7171
* {@inheritdoc}
7272
*/
73-
public function findAll()
73+
public function findAll($limit = null)
7474
{
7575
return array_map(
7676
function (TaskEntity $entity) {
7777
return $entity->getTask();
7878
},
79-
$this->taskRepository->findAll()
79+
$this->taskRepository->findBy([], null, $limit)
80+
);
81+
}
82+
83+
/**
84+
* {@inheritdoc}
85+
*/
86+
public function findByKey($key, $limit = null)
87+
{
88+
return array_map(
89+
function (TaskEntity $entity) {
90+
return $entity->getTask();
91+
},
92+
$this->taskRepository->findBy(['key' => $key], null, $limit)
8093
);
8194
}
8295

0 commit comments

Comments
 (0)