8000 [FrameworkBundle] Add support for signal plain name in the `messenger… · symfony/symfony@cd91c11 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd91c11

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[FrameworkBundle] Add support for signal plain name in the messenger.stop_worker_on_signals configuration
1 parent 3918524 commit cd91c11

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Deprecate the `--show-arguments` option of the `container:debug` command, as arguments are now always shown
1212
* Add `RateLimiterFactoryInterface` as an alias of the `limiter` service
1313
* Add `framework.validation.disable_translation` option
14+
* Add support for signal plain name in the `messenger.stop_worker_on_signals` configuration
1415

1516
7.2
1617
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $en
15721572
->{$enableIfStandalone('symfony/messenger', MessageBusInterface::class)}()
15731573
->fixXmlConfig('transport')
15741574
->fixXmlConfig('bus', 'buses')
1575+
->fixXmlConfig('stop_worker_on_signal')
15751576
->validate()
15761577
->ifTrue(fn ($v) => isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus'])
15771578
->thenInvalid('You must specify the "default_bus" if you define more than one bus.')
@@ -1704,7 +1705,26 @@ function ($a) {
17041705
->arrayNode('stop_worker_on_signals')
17051706
->defaultValue([])
17061707
->info('A list of signals that should stop the worker; defaults to SIGTERM and SIGINT.')
1707-
->integerPrototype()->end()
1708+
->beforeNormalization()
1709+
->always(function ($signals) {
1710+
if (!\is_array($signals)) {
1711+
throw new InvalidConfigurationException('The "stop_worker_on_signals" option must be an array in messenger configuration.');
1712+
}
1713+
1714+
return array_map(static function ($v) {
1715+
if (\is_string($v) && str_starts_with($v, 'SIG') && \array_key_exists($v, get_defined_constants(true)['pcntl'])) {
1716+
return \constant($v);
1717+
}
1718+
1719+
if (!\is_int($v)) {
1720+
throw new InvalidConfigurationException('The "stop_worker_on_signals" option must be an array of pcntl signals in messenger configuration.');
1721+
}
1722+
1723+
return $v;
1724+
}, $signals);
1725+
})
1726+
->end()
1727+
->scalarPrototype()->end()
17081728
->end()
17091729
->scalarNode('default_bus')->defaultNull()->end()
17101730
->arrayNode('buses')

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@
609609
<xsd:element name="routing" type="messenger_routing" minOccurs="0" maxOccurs="unbounded" />
610610
<xsd:element name="transport" type="messenger_transport" minOccurs="0" maxOccurs="unbounded" />
611611
<xsd:element name="bus" type="messenger_bus" minOccurs="0" maxOccurs="unbounded" />
612+
<xsd:element name="stop-worker-on-signal" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
612613
</xsd:sequence>
613614
<xsd:attribute name="default-bus" type="xsd:string" />
614615
<xsd:attribute name="enabled" type="xsd:boolean" />

0 commit comments

Comments
 (0)
0