Skip to content

Commit 29223a4

Browse files
authored
fix usage with crontab (#51)
1 parent b2621d0 commit 29223a4

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

.github/workflows/tasks.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Tasks
22

3-
on: push
3+
on:
4+
push:
5+
pull_request:
46

57
jobs:
68
lint-php:

Classes/EventListener/ConsoleCommandEventListener.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@
44

55
namespace Kanti\ServerTiming\EventListener;
66

7+
use Exception;
78
use Kanti\ServerTiming\Dto\ScriptResult;
8-
use Kanti\ServerTiming\SqlLogging\SqlLoggerCore11;
99
use Kanti\ServerTiming\Utility\TimingUtility;
1010
use Symfony\Component\Console\Event\ConsoleCommandEvent;
1111
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
12+
use Kanti\ServerTiming\Dto\StopWatch;
1213

1314
final class ConsoleCommandEventListener
1415
{
16+
/** @var StopWatch[] */
17+
private array $stopWatches = [];
18+
1519
public function start(ConsoleCommandEvent $event): void
1620
{
17-
TimingUtility::start('console.command', (string)$event->getCommand()?->getName());
21+
$this->stopWatches[] = TimingUtility::stopWatch('console.command', (string)$event->getCommand()?->getName());
1822
}
1923

2024
public function stop(ConsoleTerminateEvent $event): void
2125
{
22-
TimingUtility::end('console.command');
23-
TimingUtility::getInstance()->shutdown(ScriptResult::fromCli($event->getExitCode()));
26+
$stopWatch = array_pop($this->stopWatches);
27+
if ($stopWatch === null) {
28+
throw new Exception('No stopWatch found, did you start the command already?');
29+
}
30+
31+
$stopWatch->stop();
32+
if (!$this->stopWatches) {
33+
TimingUtility::getInstance()->shutdown(ScriptResult::fromCli($event->getExitCode()));
34+
}
2435
}
2536
}

0 commit comments

Comments
 (0)