Fix task(...)->once() with --parallel and --limit (#1784)

* add test to show issue with once() used with --parallel and --limit issue

* handle once() in a better way to prevent issue with --parallel and --limit
This commit is contained in:
Jérémie Augustin 2019-01-06 08:07:40 +01:00 committed by Anton Medvedev
parent 02f7585af5
commit f8ecded38c
5 changed files with 31 additions and 2 deletions

View File

@ -24,6 +24,7 @@
- Fixed Laravel `laravel_version` failure - Fixed Laravel `laravel_version` failure
- Fixed parser errors by adding the trim function to the changelog parser tokens - Fixed parser errors by adding the trim function to the changelog parser tokens
- Fixed arguments for rsync to be properly escaped - Fixed arguments for rsync to be properly escaped
- Prevent multiple execution of task()->once() with --parallel and --limit option [#1419]
## v6.3.0 ## v6.3.0

View File

@ -126,7 +126,7 @@ class ParallelExecutor implements ExecutorInterface
if ($task->shouldBePerformed($host)) { if ($task->shouldBePerformed($host)) {
$processes[$host->getHostname()] = $this->getProcess($host, $task); $processes[$host->getHostname()] = $this->getProcess($host, $task);
if ($task->isOnce()) { if ($task->isOnce()) {
break; $task->setHasRun();
} }
} }
} }

View File

@ -319,4 +319,14 @@ class Task
{ {
return $this->shallow; return $this->shallow;
} }
/**
* @internal this is used by ParallelExecutor and prevent multiple run
*/
public function setHasRun()
{
if ($this->isOnce()) {
$this->hasRun = true;
}
}
} }

View File

@ -11,7 +11,7 @@ require 'recipe/common.php';
// Hosts // Hosts
localhost('host[1:2]') localhost('host[1:4]')
->set('deploy_path', __DIR__ . '/tmp/localhost'); ->set('deploy_path', __DIR__ . '/tmp/localhost');

View File

@ -33,5 +33,23 @@ class ParallelOnceTest extends DepCase
self::assertFileExists(self::$currentPath . '/deployed-host1'); self::assertFileExists(self::$currentPath . '/deployed-host1');
self::assertFileNotExists(self::$currentPath . '/deployed-host2'); self::assertFileNotExists(self::$currentPath . '/deployed-host2');
self::assertFileNotExists(self::$currentPath . '/deployed-host3');
self::assertFileNotExists(self::$currentPath . '/deployed-host4');
}
public function testOnceWithLimit()
{
$output = $this->start('deploy', [
'--parallel' => true,
'--limit' => 2,
'--file' => DEPLOYER_FIXTURES . '/recipe/parallel.php'
], [
'verbosity' => OutputInterface::VERBOSITY_DEBUG
]);
self::assertFileExists(self::$currentPath . '/deployed-host1');
self::assertFileNotExists(self::$currentPath . '/deployed-host2');
self::assertFileNotExists(self::$currentPath . '/deployed-host3');
self::assertFileNotExists(self::$currentPath . '/deployed-host4');
} }
} }