Skip to content

Commit ef51270

Browse files
authored
Add messenger transport routing per job name (#175)
* Add messenger transport routing per job name * Fixed missing sentence end in doc * Fixed unclosed prototypes in config * Fixed potentially undefined messenger config * Fixed validate rules not set on prototyped config vars
1 parent 1bfd057 commit ef51270

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
* @phpstan-type LauncherConfig array{
3434
* default: string|null,
3535
* launchers: array<string, string>,
36+
* messenger?: array{
37+
* routing: array<string, string>,
38+
* },
3639
* }
3740
* @phpstan-type ParametersConfig array{
3841
* global: array<string, mixed>,
@@ -130,8 +133,18 @@ private function launcher(): ArrayNodeDefinition
130133
->defaultValue(['simple' => 'simple://simple'])
131134
->useAttributeAsKey('name')
132135
->scalarPrototype()
133-
->validate()
134-
->ifTrue($isInvalidDsn)->thenInvalid('Invalid job launcher DSN.')
136+
->validate()
137+
->ifTrue($isInvalidDsn)->thenInvalid('Invalid job launcher DSN.')
138+
->end()
139+
->end()
140+
->end()
141+
->arrayNode('messenger')
142+
->children()
143+
->arrayNode('routing')
144+
->normalizeKeys(false)
145+
->useAttributeAsKey('name')
146+
->scalarPrototype()->end()
147+
->end()
135148
->end()
136149
->end()
137150
->end()
@@ -164,15 +177,15 @@ private function parameters(): ArrayNodeDefinition
164177
->children()
165178
->arrayNode('global')
166179
->useAttributeAsKey('name')
167-
->variablePrototype()
168-
->end()
180+
->variablePrototype()->end()
169181
->end()
170182
->arrayNode('per_job')
171183
->useAttributeAsKey('name')
172184
->variablePrototype()
173-
->validate()
174-
->ifTrue(fn(mixed $value) => !$isStringAssociativeArray($value))
175-
->thenInvalid('Should be an array<string, mixed>.')
185+
->validate()
186+
->ifTrue(fn(mixed $value) => !$isStringAssociativeArray($value))
187+
->thenInvalid('Should be an array<string, mixed>.')
188+
->end()
176189
->end()
177190
->end()
178191
->end()

src/DependencyInjection/JobLauncherDefinitionFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Yokai\Batch\Bridge\Symfony\Console\CommandRunner;
1212
use Yokai\Batch\Bridge\Symfony\Console\RunCommandJobLauncher;
1313
use Yokai\Batch\Bridge\Symfony\Messenger\DispatchMessageJobLauncher;
14+
use Yokai\Batch\Bridge\Symfony\Messenger\MessengerJobsConfiguration;
1415
use Yokai\Batch\Launcher\JobLauncherInterface;
1516
use Yokai\Batch\Launcher\SimpleJobLauncher;
1617
use Yokai\Batch\Storage\JobExecutionStorageInterface;
@@ -71,6 +72,9 @@ private static function messenger(): Definition
7172
'$jobExecutionFactory' => new Reference('yokai_batch.job_execution_factory'),
7273
'$jobExecutionStorage' => new Reference(JobExecutionStorageInterface::class),
7374
'$messageBus' => new Reference(MessageBusInterface::class),
75+
'$messengerJobsConfiguration' => new Definition(MessengerJobsConfiguration::class, [
76+
'$routing' => '%yokai_batch.launcher.messenger_routing%',
77+
]),
7478
]);
7579
}
7680

src/DependencyInjection/YokaiBatchExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ private function configureLauncher(ContainerBuilder $container, array $config):
144144
));
145145
}
146146

147+
$container->setParameter('yokai_batch.launcher.messenger_routing', $config['messenger']['routing'] ?? []);
148+
147149
$launcherIdPerLauncherName = [];
148150
foreach ($config['launchers'] as $name => $dsn) {
149151
$definitionOrReference = JobLauncherDefinitionFactory::fromDsn($dsn);

0 commit comments

Comments
 (0)