Skip to content

Commit

Permalink
long running process doctrine connection listener
Browse files Browse the repository at this point in the history
  • Loading branch information
alli83 committed Apr 16, 2024
1 parent f966567 commit 36a7031
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ private function addDbalSection(ArrayNodeDefinition $node): void
->children()
->scalarNode('default_connection')->end()
->end()
->children()
->integerNode('check_connection_timing')->end()
->fixXmlConfig('type')
->children()
->arrayNode('types')
Expand Down Expand Up @@ -223,6 +225,7 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->scalarNode('server_version')->end()
->scalarNode('driver_class')->end()
->scalarNode('wrapper_class')->end()
->scalarNode('check_connection_frequency')->defaultValue(30)->end()
->booleanNode('keep_slave')
->setDeprecated(
'doctrine/doctrine-bundle',
Expand Down
12 changes: 12 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$config['default_connection'] = reset($keys);
}

if (! $container->hasParameter('kernel.runtime_mode') && ! $container->hasParameter('kernel.runtime_mode.worker')) {
$container->removeDefinition('doctrine.listeners.doctrine_connection_listener');
} else {
$container->getDefinition('doctrine.orm.listeners.doctrine_connection_listener')->setArgument(1, $config['check_connection_timing']);

Check failure on line 180 in DependencyInjection/DoctrineExtension.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

InvalidArrayOffset

DependencyInjection/DoctrineExtension.php:180:110: InvalidArrayOffset: Cannot access value on variable $config using offset value of 'check_connection_timing', expecting 'connections', 'driver_schemes', 'default_connection' or 'types' (see https://psalm.dev/115)
}

$this->defaultConnection = $config['default_connection'];

$container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $this->defaultConnection));
Expand Down Expand Up @@ -252,6 +258,12 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
$connection['profiling_collect_schema_errors'],
);

if (isset($connection['check_connection_timing'])) {
if ($container->hasParameter('kernel.runtime_mode') || $container->hasParameter('kernel.runtime_mode.worker')) {
$configuration->addMethodCall('setCheckConnectionTiming', [$connection['check_connection_timing']]);
}
}

if (isset($connection['auto_commit'])) {
$configuration->addMethodCall('setAutoCommit', [$connection['auto_commit']]);
}
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/dbal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
<tag name="controller.service_arguments" />
</service>

<service id="doctrine.listeners.doctrine_connection_listener" class="Symfony\Bridge\Doctrine\Listener\ConnectionListener">
<argument type="service" id="service_container" />
<argument /> <!-- check timing -->
<tag name="kernel.event_subscriber" />
</service>

<service id="doctrine.dbal.default_schema_manager_factory" class="Doctrine\DBAL\Schema\DefaultSchemaManagerFactory" />
<service id="doctrine.dbal.legacy_schema_manager_factory" class="Doctrine\DBAL\Schema\LegacySchemaManagerFactory" />

Expand Down

0 comments on commit 36a7031

Please sign in to comment.