diff --git a/Classes/Command/TaskCommandController.php b/Classes/Command/TaskCommandController.php index fd3fde9..0a7c9b4 100644 --- a/Classes/Command/TaskCommandController.php +++ b/Classes/Command/TaskCommandController.php @@ -11,6 +11,9 @@ use Assert\Assertion; use Neos\Flow\Persistence\PersistenceManagerInterface; +use Neos\Flow\Utility\Environment; +use Neos\Utility\Files; +use Neos\Utility\Lock\LockManager; use Ttree\Scheduler\Domain\Model\Task; use Ttree\Scheduler\Service\TaskService; use Ttree\Scheduler\Task\TaskInterface; @@ -44,17 +47,42 @@ class TaskCommandController extends CommandController */ protected $persistenceManager; + /** + * @var Environment + * @Flow\Inject + */ + protected $environment; + /** * @Flow\InjectConfiguration(package="Ttree.Scheduler", path="allowParallelExecution") * @var boolean */ protected $allowParallelExecution = true; + /** + * @Flow\InjectConfiguration(package="Ttree.Scheduler", path="lockStrategyClassName") + * @var boolean + */ + protected $lockStrategyClassName = ''; + /** * @var Lock */ protected $parallelExecutionLock; + /** + * @throws \Neos\Flow\Utility\Exception + * @throws \Neos\Utility\Exception\FilesException + */ + public function initializeObject(): void + { + $lockManager = new LockManager($this->lockStrategyClassName, ['lockDirectory' => Files::concatenatePaths([ + $this->environment->getPathToTemporaryDirectory(), + 'Lock' + ])]); + Lock::setLockManager($lockManager); + } + /** * Run all pending task * @@ -62,7 +90,6 @@ class TaskCommandController extends CommandController */ public function runCommand($dryRun = false) { - if ($this->allowParallelExecution !== true) { try { $this->parallelExecutionLock = new Lock('Ttree.Scheduler.ParallelExecutionLock'); diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 699fca2..b60344e 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -1,6 +1,7 @@ Ttree: Scheduler: allowParallelExecution: true + lockStrategyClassName: 'Neos\Utility\Lock\FlockLockStrategy' Neos: Flow: object: diff --git a/composer.json b/composer.json index 25ca401..db589b0 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "require": { "neos/flow": "^7.0", "mtdowling/cron-expression": "^1.2", - "beberlei/assert": "^2.7" + "beberlei/assert": "^2.7", + "neos/utility-lock": "^5.3" }, "autoload": { "psr-4": {