Skip to content
Commits on Source (3)
......@@ -53,9 +53,12 @@ After deployment run
This will signal the workers to exit after the current task, which means they
will be restarted by supervisor and will run the newly deployed code.
## Manage Workers with Supervisor
Symfony
[recommends](https://symfony.com/doc/current/messenger.html#supervisor-configuration)
to use [Supervisor](http://supervisord.org/) to do this.
to use [Supervisor](http://supervisord.org/) to handle worker jobs and restart them.
```bash
sudo apt-get install supervisor
......
......@@ -174,7 +174,7 @@ class DbpRelayCoreExtension extends ConfigurableExtension implements PrependExte
$routing = array_merge($routing, $container->getParameter('dbp_api.messenger_routing'));
if ($messengerTransportDsn === '') {
throw new \RuntimeException('A bundle requires a messenger: set "messenger_transport_dsn" in the core bundle config');
throw new \RuntimeException('A bundle requires a worker queue: set "queue_dsn" in the core bundle config');
}
$container->loadFromExtension('framework', [
......@@ -185,6 +185,19 @@ class DbpRelayCoreExtension extends ConfigurableExtension implements PrependExte
'routing' => $routing,
],
]);
} else {
// By always setting a transport, we ensure that the messenger commands work in all cases, even if they
// are not stricly needed
if ($messengerTransportDsn === '') {
$messengerTransportDsn = 'in-memory://dummy-queue-not-configured';
}
$container->loadFromExtension('framework', [
'messenger' => [
'transports' => [
'async' => $messengerTransportDsn,
],
],
]);
}
// https://symfony.com/doc/5.3/components/lock.html
......
......@@ -56,6 +56,8 @@ class TransportFactoryDecorator implements TransportFactoryInterface, LoggerAwar
// Use the new recommended default:
// https://github.com/symfony/symfony/pull/42163
$options['delete_after_ack'] = true;
} elseif ($dsn === 'in-memory://dummy-queue-not-configured') {
// This is used when no queue is configured, so allow it.
} else {
throw new \Exception('Only redis currently supported as a messenger transport (current DSN: '.$dsn.')');
}
......
......@@ -15,7 +15,7 @@ class RestartCommandTest extends KernelTestCase
$kernel = static::createKernel();
$application = new Application($kernel);
$command = $application->find('dbp:relay:queue:restart');
$command = $application->find('dbp:relay:core:queue:restart');
$commandTester = new CommandTester($command);
$res = $commandTester->execute([]);
$this->assertSame(0, $res);
......