Skip to content

Commit ef8ca12

Browse files
committed
feature #146 Adding debug command to show active tasks (Nyholm)
This PR was merged into the master branch. Discussion ---------- Adding debug command to show active tasks This is useful to see if Carson actually schedule things for later. <img width="740" alt="Screenshot 2020-12-18 at 16 36 30" src="https://user-images.githubusercontent.com/1275206/102632314-37d72300-414f-11eb-81f3-f3e25cc9e341.png"> Commits ------- d3e7aa4 Adding debug command to show active tasks
2 parents 1fcc0a7 + d3e7aa4 commit ef8ca12

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/Command/ListTaskCommand.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Command;
6+
7+
use App\Entity\Task;
8+
use App\Repository\TaskRepository;
9+
use Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
use Symfony\Component\Console\Style\SymfonyStyle;
14+
15+
/**
16+
* @author Tobias Nyholm <[email protected]>
17+
*/
18+
class ListTaskCommand extends Command
19+
{
20+
protected static $defaultName = 'app:task:list';
21+
private $repository;
22+
23+
public function __construct(TaskRepository $repository)
24+
{
25+
parent::__construct();
26+
$this->repository = $repository;
27+
}
28+
29+
protected function configure()
30+
{
31+
$this->addOption('number', null, InputOption::VALUE_REQUIRED, 'The issue number we are interested in', null);
32+
}
33+
34+
protected function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
/** @var int|null $number */
37+
$number = $input->getOption('number');
38+
if (null === $number) {
39+
$criteria = [];
40+
} else {
41+
$criteria = ['number' => $number];
42+
}
43+
44+
$limit = 100;
45+
$tasks = $this->repository->findBy($criteria, ['verifyAfter' => 'ASC'], $limit);
46+
$rows = [];
47+
foreach ($tasks as $task) {
48+
$rows[] = [
49+
$task->getRepositoryFullName(),
50+
$task->getNumber(),
51+
$this->actionToString($task->getAction()),
52+
$task->getVerifyAfter()->format('Y-m-d H:i:s'),
53+
];
54+
}
55+
56+
$io = new SymfonyStyle($input, $output);
57+
$io->table(['Repo', 'Number', 'Action', 'Verify After'], $rows);
58+
$io->write(sprintf('Total of %d items in the table. ', $taskCount = count($tasks)));
59+
if ($limit === $taskCount) {
60+
$io->write('There might be more tasks in the database.');
61+
}
62+
$io->newLine();
63+
64+
return 0;
65+
}
66+
67+
private function actionToString(int $action): string
68+
{
69+
$data = [
70+
Task::ACTION_CLOSE_STALE => 'Close stale',
71+
Task::ACTION_CLOSE_DRAFT => 'Close draft',
72+
Task::ACTION_INFORM_CLOSE_STALE => 'Inform about close',
73+
];
74+
75+
return $data[$action] ?? 'Unknown action';
76+
}
77+
}

src/Entity/Task.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public function getAction(): int
9999
return $this->action;
100100
}
101101

102+
public function getVerifyAfter(): \DateTimeImmutable
103+
{
104+
return $this->verifyAfter;
105+
}
106+
102107
public function setVerifyAfter(\DateTimeImmutable $verifyAfter): void
103108
{
104109
$this->verifyAfter = $verifyAfter;

0 commit comments

Comments
 (0)