Skip to content

Commit 8cd9e69

Browse files
committed
add cron expression and next due to info
1 parent ed03a5e commit 8cd9e69

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/SymfonyConsoleEventListener.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace JobRunner\JobRunner\SymfonyConsole;
66

7+
use Cron\CronExpression;
78
use JobRunner\JobRunner\Event\JobEvent;
89
use JobRunner\JobRunner\Event\JobFailEvent;
910
use JobRunner\JobRunner\Event\JobIsLockedEvent;
@@ -25,7 +26,7 @@ public function __construct(
2526
private readonly ConsoleSectionOutput $tableSection,
2627
private readonly Table $table,
2728
) {
28-
$this->table->setHeaders(['Job name', 'state', 'output']);
29+
$this->table->setHeaders(['Job name', 'cron expression', 'next run date', 'state', 'output']);
2930
}
3031

3132
public function start(Job $job): void
@@ -55,7 +56,13 @@ public function isLocked(Job $job): void
5556

5657
private function doIt(Job $job, string $state, string|null $output = null): void
5758
{
58-
$this->rows[$job->getName()] = [$job->getName(), $state, $output];
59+
$this->rows[$job->getName()] = [
60+
$job->getName(),
61+
$job->getCronExpression(),
62+
(new CronExpression($job->getCronExpression()))->getNextRunDate()->format('Y-m-d H:i:s'),
63+
$state,
64+
$output,
65+
];
5966
$this->tableSection->clear();
6067
$this->table->setRows(array_values($this->rows));
6168
$this->table->render();

tests/Unit/SymfonyConsoleEventListenerTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace JobRunner\JobRunner\SymfonyConsole\Tests\Unit;
66

7+
use DateTimeImmutable;
78
use JobRunner\JobRunner\Job\Job;
89
use JobRunner\JobRunner\SymfonyConsole\SymfonyConsoleEventListener;
910
use PHPUnit\Framework\TestCase;
@@ -34,18 +35,20 @@ public function testSuccess(): void
3435
$table = self::createMock(Table::class);
3536
$consoleSectionOutput = self::createMock(ConsoleSectionOutput::class);
3637
$job = self::createMock(Job::class);
38+
$nextHour = (new DateTimeImmutable())->setTime((int) (new DateTimeImmutable())->modify('+1 hour')->format('H'), 0, 0);
3739

3840
$table->expects($this->exactly(5))->method('render');
3941
$job->expects($this->any())->method('getName')->willReturn('myName');
42+
$job->expects($this->any())->method('getCronExpression')->willReturn('0 * * * *');
4043
$consoleSectionOutput->expects($this->exactly(5))->method('clear');
41-
$table->expects($this->once())->method('setHeaders')->with(['Job name', 'state', 'output']);
42-
$table->expects($this->exactly(5))->method('setRows')->with($this->callback(function (mixed $param) {
44+
$table->expects($this->once())->method('setHeaders')->with(['Job name', 'cron expression', 'next run date', 'state', 'output']);
45+
$table->expects($this->exactly(5))->method('setRows')->with($this->callback(function (mixed $param) use ($nextHour) {
4346
return $param === match ($this->getNextIncrement('setRows')) {
44-
1 => [['myName', 'start', null]],
45-
2 => [['myName', 'fail', 'toto']],
46-
3 => [['myName', 'notDue', null]],
47-
4 => [['myName', 'isLocked', null]],
48-
5 => [['myName', 'success', 'toto']],
47+
1 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'start', null]],
48+
2 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'fail', 'toto']],
49+
3 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'notDue', null]],
50+
4 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'isLocked', null]],
51+
5 => [['myName', '0 * * * *', $nextHour->format('Y-m-d H:i:s'), 'success', 'toto']],
4952
};
5053
}));
5154

0 commit comments

Comments
 (0)