Skip to content

Commit d5c497c

Browse files
committed
multi client configuration
1 parent 1351930 commit d5c497c

File tree

10 files changed

+70
-37
lines changed

10 files changed

+70
-37
lines changed

docs/bundle/config_reference.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enqueue:
4343

4444
# the time in milliseconds queue consumer waits for a message (100 ms by default)
4545
receive_timeout: 100
46+
job: false
4647
async_commands:
4748
enabled: false
4849
extensions:

pkg/enqueue-bundle/DependencyInjection/Configuration.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Enqueue\Bundle\DependencyInjection;
44

55
use Enqueue\AsyncCommand\RunCommandProcessor;
6+
use Enqueue\JobQueue\Job;
67
use Enqueue\Monitoring\Symfony\DependencyInjection\MonitoringFactory;
78
use Enqueue\Symfony\Client\DependencyInjection\ClientFactory;
89
use Enqueue\Symfony\DependencyInjection\TransportFactory;
@@ -35,6 +36,7 @@ public function getConfigTreeBuilder(): TreeBuilder
3536
->append(ClientFactory::getConfiguration($this->debug))
3637
->append($this->getMonitoringConfiguration())
3738
->append($this->getAsyncCommandsConfiguration())
39+
->append($this->getJobConfiguration())
3840
->arrayNode('extensions')->addDefaultsIfNotSet()->children()
3941
->booleanNode('doctrine_ping_connection_extension')->defaultFalse()->end()
4042
->booleanNode('doctrine_clear_identity_map_extension')->defaultFalse()->end()
@@ -46,7 +48,6 @@ public function getConfigTreeBuilder(): TreeBuilder
4648
;
4749

4850
// $rootNode->children()
49-
// ->booleanNode('job')->defaultFalse()->end()
5051
// ->arrayNode('async_events')
5152
// ->addDefaultsIfNotSet()
5253
// ->canBeEnabled()
@@ -76,4 +77,16 @@ private function getAsyncCommandsConfiguration(): ArrayNodeDefinition
7677
->canBeEnabled()
7778
;
7879
}
80+
81+
private function getJobConfiguration(): ArrayNodeDefinition
82+
{
83+
if (false === class_exists(Job::class)) {
84+
return MissingComponentFactory::getConfiguration('job', ['enqueue/job-queue']);
85+
}
86+
87+
return (new ArrayNodeDefinition('job'))
88+
->addDefaultsIfNotSet()
89+
->canBeEnabled()
90+
;
91+
}
7992
}

pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public function load(array $configs, ContainerBuilder $container): void
8484
$monitoringFactory->buildClientExtension($container, $configs['monitoring']);
8585
}
8686
}
87+
88+
// job-queue
89+
if (false == empty($configs['job']['enabled'])) {
90+
if (false === isset($configs['client'])) {
91+
throw new \LogicException('Client is required for job-queue.');
92+
}
93+
94+
if ($name !== $defaultName) {
95+
throw new \LogicException('Job-queue supports only default configuration.');
96+
}
97+
98+
$loader->load('job.yml');
99+
}
87100
}
88101

89102
$defaultClient = null;
@@ -113,14 +126,6 @@ public function load(array $configs, ContainerBuilder $container): void
113126
$this->loadSignalExtension($config, $container);
114127
$this->loadReplyExtension($config, $container);
115128

116-
// if ($config['job']) {
117-
// if (!class_exists(Job::class)) {
118-
// throw new \LogicException('Seems "enqueue/job-queue" is not installed. Please fix this issue.');
119-
// }
120-
//
121-
// $loader->load('job.yml');
122-
// }
123-
//
124129
// if ($config['async_events']['enabled']) {
125130
// if (false == class_exists(AsyncEventDispatcherExtension::class)) {
126131
// throw new \LogicException('The "enqueue/async-event-dispatcher" package has to be installed.');

pkg/enqueue-bundle/Resources/config/job.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
public: true
2121
arguments:
2222
- '@Enqueue\JobQueue\Doctrine\JobStorage'
23-
- '@enqueue.client.default.producer'
23+
- '@Enqueue\Client\ProducerInterface'
2424

2525
# Deprecated. To be removed in 0.10.
2626
enqueue.job.processor:
@@ -55,7 +55,7 @@ services:
5555
arguments:
5656
- '@Enqueue\JobQueue\Doctrine\JobStorage'
5757
- '@Enqueue\JobQueue\CalculateRootJobStatusService'
58-
- '@enqueue.client.default.producer'
58+
- '@Enqueue\Client\ProducerInterface'
5959
- '@logger'
6060
tags:
6161
- { name: 'enqueue.command_subscriber', client: 'default' }
@@ -70,7 +70,7 @@ services:
7070
public: true
7171
arguments:
7272
- '@Enqueue\JobQueue\Doctrine\JobStorage'
73-
- '@enqueue.client.default.producer'
73+
- '@Enqueue\Client\ProducerInterface'
7474
- '@logger'
7575
tags:
7676
- { name: 'enqueue.topic_subscriber', client: 'default' }

pkg/enqueue-bundle/Tests/Functional/Job/CalculateRootJobStatusProcessorTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class CalculateRootJobStatusProcessorTest extends WebTestCase
1212
{
1313
public function testCouldBeConstructedByContainer()
1414
{
15-
$this->markTestSkipped('Configuration for jobs is not yet ready');
16-
1715
$instance = static::$container->get(CalculateRootJobStatusProcessor::class);
1816

1917
$this->assertInstanceOf(CalculateRootJobStatusProcessor::class, $instance);

pkg/enqueue-bundle/Tests/Functional/Job/DependentJobServiceTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class DependentJobServiceTest extends WebTestCase
1212
{
1313
public function testCouldBeConstructedByContainer()
1414
{
15-
$this->markTestSkipped('Configuration for jobs is not yet ready');
16-
1715
$instance = static::$container->get(DependentJobService::class);
1816

1917
$this->assertInstanceOf(DependentJobService::class, $instance);

pkg/enqueue-bundle/Tests/Functional/Job/JobRunnerTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class JobRunnerTest extends WebTestCase
1212
{
1313
public function testCouldBeConstructedByContainer()
1414
{
15-
$this->markTestSkipped('Configuration for jobs is not yet ready');
16-
1715
$instance = static::$container->get(JobRunner::class);
1816

1917
$this->assertInstanceOf(JobRunner::class, $instance);

pkg/enqueue-bundle/Tests/Functional/Job/JobStorageTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class JobStorageTest extends WebTestCase
1212
{
1313
public function testCouldGetJobStorageAsServiceFromContainer()
1414
{
15-
$this->markTestSkipped('Configuration for jobs is not yet ready');
16-
1715
$instance = static::$container->get(JobStorage::class);
1816

1917
$this->assertInstanceOf(JobStorage::class, $instance);

pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -160,34 +160,38 @@ public function testShouldThrowExceptionIfDefaultProcessorQueueIsEmpty()
160160

161161
public function testJobShouldBeDisabledByDefault()
162162
{
163-
$this->markTestSkipped('Configuration for jobs is not yet ready');
164-
165163
$configuration = new Configuration(true);
166164

167165
$processor = new Processor();
168166
$config = $processor->processConfiguration($configuration, [[
169-
'transport' => [],
167+
'default' => [
168+
'transport' => [],
169+
],
170170
]]);
171171

172172
$this->assertArraySubset([
173-
'job' => false,
173+
'default' => [
174+
'job' => false,
175+
],
174176
], $config);
175177
}
176178

177179
public function testCouldEnableJob()
178180
{
179-
$this->markTestSkipped('Configuration for jobs is not yet ready');
180-
181181
$configuration = new Configuration(true);
182182

183183
$processor = new Processor();
184184
$config = $processor->processConfiguration($configuration, [[
185-
'transport' => [],
186-
'job' => true,
185+
'default' => [
186+
'transport' => [],
187+
'job' => true,
188+
],
187189
]]);
188190

189191
$this->assertArraySubset([
190-
'job' => true,
192+
'default' => [
193+
'job' => true,
194+
],
191195
], $config);
192196
}
193197

pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php

+26-8
Original file line numberDiff line numberDiff line change
@@ -255,31 +255,49 @@ public function testShouldNotLoadDelayRedeliveredMessageExtensionIfRedeliveredDe
255255

256256
public function testShouldLoadJobServicesIfEnabled()
257257
{
258-
$this->markTestSkipped('Configuration for jobs is not yet ready');
259-
260258
$container = $this->getContainerBuilder(true);
261259

262260
$extension = new EnqueueExtension();
263261

264262
$extension->load([[
265-
'transport' => [],
266-
'job' => true,
263+
'default' => [
264+
'transport' => [],
265+
'client' => null,
266+
'job' => true,
267+
],
267268
]], $container);
268269

269270
self::assertTrue($container->hasDefinition(JobRunner::class));
270271
}
271272

272-
public function testShouldNotLoadJobServicesIfDisabled()
273+
public function testShouldThrowExceptionIfClientIsNotEnabledOnJobLoad()
273274
{
274-
$this->markTestSkipped('Configuration for jobs is not yet ready');
275+
$this->expectException(\LogicException::class);
276+
$this->expectExceptionMessage('Client is required for job-queue.');
277+
278+
$container = $this->getContainerBuilder(true);
279+
280+
$extension = new EnqueueExtension();
281+
282+
$extension->load([[
283+
'default' => [
284+
'transport' => [],
285+
'job' => true,
286+
],
287+
]], $container);
288+
}
275289

290+
public function testShouldNotLoadJobServicesIfDisabled()
291+
{
276292
$container = $this->getContainerBuilder(true);
277293

278294
$extension = new EnqueueExtension();
279295

280296
$extension->load([[
281-
'transport' => [],
282-
'job' => false,
297+
'default' => [
298+
'transport' => [],
299+
'job' => false,
300+
],
283301
]], $container);
284302

285303
self::assertFalse($container->hasDefinition(JobRunner::class));

0 commit comments

Comments
 (0)