-
Notifications
You must be signed in to change notification settings - Fork 12
feat: implement ConsoleCommandListener #42
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
feat: implement ConsoleCommandListener #42
Conversation
Oliboy50
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤞 👏 🤷
| - php-version: '8.1' | ||
| symfony-version: '^7.0' | ||
| php-version: ['8.2', '8.3', '8.4'] | ||
| symfony-version: ['^6.4', '^7.0'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand the purpose of this PR, because you talked about Symfony 7.3, but this bundle seemed to already be tested against Symfony ^7.0, so:
did our tests were not covering enough things and were not proving that Symfony 7.0 was not supported correctly? 😢
or did Symfony introduced a breaking change between 7.0 and 7.4? 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explain in the opened issue, the bug appears from symfony 7.3:
When updating to sf >= 7.3 projects based on DaemonBundle fails since symfony Command implements the SignalableCommandInterface from its 7.3 version.
This interface define the function:
public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false;
that conflict with the one defined into DaemonCommand
To resolve this issue I propose to handle signal by adding a src/EventListener/ConsoleCommandListener.php that hanlde the signal instead of to add signal handler directly in the DaemonCommand contructor:
// Add the signal handler pcntl_signal(SIGTERM, [$this, 'handleSignal']); pcntl_signal(SIGINT, [$this, 'handleSignal']);
Concerning the ci.yml I just updated the matrix by adding php 8.3, php 8.4 and removing 8.1 as long as It will be no more supported at the end of the month of december
928dddc to
3288fba
Compare
|
Just squashed my commits |
|
UP, please may the 2nd reviewer review, accept or reject. Our team need it, elsewhere we will go on forked solution. |
This pull request refactors the handling of OS signals for daemon commands by introducing a dedicated
ConsoleCommandListenerthat responds to Symfony'sConsoleSignalEvent. The signal handling logic is moved out ofDaemonCommand, and comprehensive unit and integration tests are added to ensure correct behavior. The documentation is also updated to describe the new testing strategy and best practices.Event-driven signal handling and listener introduction:
ConsoleCommandListenerclass that listens forConsoleSignalEventand triggers shutdown onDaemonCommandinstances when receiving SIGTERM or SIGINT, using Symfony's event system and PHP 8 attributes. (src/EventListener/ConsoleCommandListener.php)handleSignalmethod and related signal handler registration fromDaemonCommand, making signal handling fully event-driven. (src/Command/DaemonCommand.php) [1] [2]Testing improvements:
tests/Unit/EventListener/ConsoleCommandListenerTest.php)tests/Integration/EventListener/ConsoleCommandListenerIntegrationTest.php)DaemonCommandConcreteto include anisShutdownRequested()helper for easier assertions in tests. (tests/Fixtures/Command/DaemonCommandConcrete.php)DaemonCommandTest. (tests/Unit/Command/DaemonCommandTest.php)Documentation updates:
docs/CONSOLE_COMMAND_LISTENER_TESTS.md)