Skip to content

Commit

Permalink
minor symfony#20646 [FrameworkBundle] Allow to pass signals to `StopW…
Browse files Browse the repository at this point in the history
…orkerOnSignalsListener` in XML config and as plain strings (alexandre-daubois)

This PR was merged into the 7.3 branch.

Discussion
----------

[FrameworkBundle] Allow to pass signals to `StopWorkerOnSignalsListener` in XML config and as plain strings

Closes symfony#20645

Commits
-------

cf1d8f1 [FrameworkBundle] Allow to pass signals to `StopWorkerOnSignalsListener` in XML config and as plain strings
  • Loading branch information
javiereguiluz committed Feb 12, 2025
2 parents bed495c + cf1d8f1 commit be0784d
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,56 @@ message before terminating.

However, you might prefer to use different POSIX signals for graceful shutdown.
You can override default ones by setting the ``framework.messenger.stop_worker_on_signals``
configuration option.
configuration option:

.. configuration-block::

.. code-block:: yaml
# config/packages/messenger.yaml
framework:
messenger:
stop_worker_on_signals:
- SIGTERM
- SIGINT
- SIGUSR1
.. code-block:: xml
<!-- config/packages/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:messenger>
<!-- ... -->
<framework:stop-worker-on-signal>SIGTERM</framework:stop-worker-on-signal>
<framework:stop-worker-on-signal>SIGINT</framework:stop-worker-on-signal>
<framework:stop-worker-on-signal>SIGUSR1</framework:stop-worker-on-signal>
</framework:messenger>
</framework:config>
</container>
.. code-block:: php
// config/packages/messenger.php
use Symfony\Config\FrameworkConfig;
return static function (FrameworkConfig $framework): void {
$framework->messenger()
->stopWorkerOnSignals(['SIGTERM', 'SIGINT', 'SIGUSR1']);
};
.. versionadded:: 7.3

Support for signals plain name in configuration was introduced in Symfony 7.3.
Prior to this, you had to use the numeric values of the signals as defined
in the ``pcntl`` extension's `predefined constants`_.

In some cases the ``SIGTERM`` signal is sent by Supervisor itself (e.g. stopping
a Docker container having Supervisor as its entrypoint). In these cases you
Expand Down Expand Up @@ -3587,3 +3636,4 @@ Learn more
.. _`high connection churn`: https://www.rabbitmq.com/connections.html#high-connection-churn
.. _`article about CQRS`: https://martinfowler.com/bliki/CQRS.html
.. _`SSL context options`: https://php.net/context.ssl
.. _`predefined constants`: https://www.php.net/pcntl.constants

0 comments on commit be0784d

Please sign in to comment.