Skip to content

Commit

Permalink
TASK: add neos/utility-lock and configure a lockManager to reenable Lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Keuerleber committed Oct 12, 2021
1 parent df3829d commit 4aee6d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
29 changes: 28 additions & 1 deletion Classes/Command/TaskCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,25 +47,49 @@ 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
*
* @param boolean $dryRun do not execute tasks
*/
public function runCommand($dryRun = false)
{

if ($this->allowParallelExecution !== true) {
try {
$this->parallelExecutionLock = new Lock('Ttree.Scheduler.ParallelExecutionLock');
Expand Down
1 change: 1 addition & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Ttree:
Scheduler:
allowParallelExecution: true
lockStrategyClassName: 'Neos\Utility\Lock\FlockLockStrategy'
Neos:
Flow:
object:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 4aee6d2

Please sign in to comment.