Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix usage with crontab #51

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/tasks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Tasks

on: push
on:
push:
pull_request:

jobs:
lint-php:
Expand Down
19 changes: 15 additions & 4 deletions Classes/EventListener/ConsoleCommandEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@

namespace Kanti\ServerTiming\EventListener;

use Exception;
use Kanti\ServerTiming\Dto\ScriptResult;
use Kanti\ServerTiming\SqlLogging\SqlLoggerCore11;
use Kanti\ServerTiming\Utility\TimingUtility;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Kanti\ServerTiming\Dto\StopWatch;

final class ConsoleCommandEventListener
{
/** @var StopWatch[] */
private array $stopWatches = [];

public function start(ConsoleCommandEvent $event): void
{
TimingUtility::start('console.command', (string)$event->getCommand()?->getName());
$this->stopWatches[] = TimingUtility::stopWatch('console.command', (string)$event->getCommand()?->getName());
}

public function stop(ConsoleTerminateEvent $event): void
{
TimingUtility::end('console.command');
TimingUtility::getInstance()->shutdown(ScriptResult::fromCli($event->getExitCode()));
$stopWatch = array_pop($this->stopWatches);
if ($stopWatch === null) {
throw new Exception('No stopWatch found, did you start the command already?');
}

$stopWatch->stop();
if (!$this->stopWatches) {
TimingUtility::getInstance()->shutdown(ScriptResult::fromCli($event->getExitCode()));
}
}
}
Loading