From ff4a807efb57ca4dd0e5ab7e4455391d8c124b5a Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Mon, 15 May 2017 11:32:59 +0200 Subject: [PATCH] removed strategy from locking configuration --- src/DependencyInjection/Configuration.php | 1 + src/DependencyInjection/TaskExtension.php | 6 ++++-- src/Locking/NullLock.php | 9 ++++----- src/Resources/config/locking/services.xml | 4 +--- tests/Functional/Command/ScheduleTaskCommandTest.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 361dede..6f3efef 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -67,6 +67,7 @@ public function getConfigTreeBuilder() ->values(array_keys($this->lockingStorageAliases)) ->defaultValue('file') ->end() + ->integerNode('ttl')->defaultValue(600)->end() ->arrayNode('storages') ->addDefaultsIfNotSet() ->children() diff --git a/src/DependencyInjection/TaskExtension.php b/src/DependencyInjection/TaskExtension.php index a89e7e1..3ad2f10 100644 --- a/src/DependencyInjection/TaskExtension.php +++ b/src/DependencyInjection/TaskExtension.php @@ -53,7 +53,7 @@ public function load(array $configs, ContainerBuilder $container) } $this->loadDoctrineAdapter($config['adapters']['doctrine'], $container); - $this->loadLockingComponent($config['locking'], $loader); + $this->loadLockingComponent($config['locking'], $container, $loader); } /** @@ -82,14 +82,16 @@ private function loadDoctrineAdapter(array $config, ContainerBuilder $container) * * @param array $config * @param LoaderInterface $loader + * @param ContainerBuilder $container */ - private function loadLockingComponent(array $config, LoaderInterface $loader) + private function loadLockingComponent(array $config, ContainerBuilder $container, LoaderInterface $loader) { if (!$config['enabled']) { return $loader->load('locking/null.xml'); } $loader->load('locking/services.xml'); + $container->setParameter('task.lock.ttl', $config['ttl']); } /** diff --git a/src/Locking/NullLock.php b/src/Locking/NullLock.php index 9fafaf4..cb0c914 100644 --- a/src/Locking/NullLock.php +++ b/src/Locking/NullLock.php @@ -11,7 +11,6 @@ namespace Task\TaskBundle\Locking; -use Task\Execution\TaskExecutionInterface; use Task\Lock\LockInterface; /** @@ -22,7 +21,7 @@ class NullLock implements LockInterface /** * {@inheritdoc} */ - public function acquire(TaskExecutionInterface $execution) + public function acquire($task) { return true; } @@ -30,7 +29,7 @@ public function acquire(TaskExecutionInterface $execution) /** * {@inheritdoc} */ - public function refresh(TaskExecutionInterface $execution) + public function refresh($task) { return true; } @@ -38,7 +37,7 @@ public function refresh(TaskExecutionInterface $execution) /** * {@inheritdoc} */ - public function release(TaskExecutionInterface $execution) + public function release($task) { return true; } @@ -46,7 +45,7 @@ public function release(TaskExecutionInterface $execution) /** * {@inheritdoc} */ - public function isAcquired(TaskExecutionInterface $execution) + public function isAcquired($task) { return false; } diff --git a/src/Resources/config/locking/services.xml b/src/Resources/config/locking/services.xml index 4544787..25488c8 100644 --- a/src/Resources/config/locking/services.xml +++ b/src/Resources/config/locking/services.xml @@ -3,11 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - + %task.lock.ttl% diff --git a/tests/Functional/Command/ScheduleTaskCommandTest.php b/tests/Functional/Command/ScheduleTaskCommandTest.php index b88696a..010a5ed 100644 --- a/tests/Functional/Command/ScheduleTaskCommandTest.php +++ b/tests/Functional/Command/ScheduleTaskCommandTest.php @@ -94,7 +94,7 @@ public function testExecuteWithWorkloadAndIntervalAndEndDate() $this->assertEquals(TestHandler::class, $tasks[0]->getHandlerClass()); $this->assertEquals('Test workload 1', $tasks[0]->getWorkload()); $this->assertEquals('0 * * * *', $tasks[0]->getInterval()); - $this->assertEquals($date, $tasks[0]->getLastExecution()); + $this->assertEquals($date, $tasks[0]->getLastExecution(), '', 2); } public function testExecuteWithExecutionDate()