|
1
|
|
|
<?php |
|
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Deployer\Executor; |
|
9
|
|
|
|
|
10
|
|
|
use Deployer\Console\Output\OutputWatcher; |
|
11
|
|
|
use Deployer\Server\Environment; |
|
12
|
|
|
use Deployer\Task\Context; |
|
13
|
|
|
use Deployer\Task\NonFatalException; |
|
14
|
|
|
|
|
15
|
|
|
class SeriesExecutor implements ExecutorInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
12 |
|
public function run($tasks, $servers, $environments, $input, $output) |
|
21
|
|
|
{ |
|
22
|
12 |
|
$output = new OutputWatcher($output); |
|
23
|
12 |
|
$informer = new Informer($output); |
|
24
|
|
|
|
|
25
|
12 |
|
foreach ($tasks as $task) { |
|
26
|
12 |
|
$success = true; |
|
27
|
12 |
|
$informer->startTask($task->getName()); |
|
28
|
|
|
|
|
29
|
12 |
|
if ($task->isOnce()) { |
|
30
|
1 |
|
$task->run(new Context(null, null, $input, $output)); |
|
31
|
1 |
|
} else { |
|
32
|
12 |
|
foreach ($servers as $serverName => $server) { |
|
33
|
12 |
|
if ($task->runOnServer($serverName)) { |
|
34
|
12 |
|
$env = isset($environments[$serverName]) ? $environments[$serverName] : $environments[$serverName] = new Environment(); |
|
35
|
|
|
|
|
36
|
12 |
View Code Duplication |
if (count($task->getOnlyForStage()) > 0 && (!$env->has('stages') || !$task->runForStages($env->get('stages')))) { |
|
|
|
|
|
|
37
|
1 |
|
continue; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
12 |
|
$informer->onServer($serverName); |
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
12 |
|
$task->run(new Context($server, $env, $input, $output)); |
|
44
|
12 |
|
} catch (NonFatalException $exception) { |
|
45
|
|
|
$success = false; |
|
46
|
|
|
$informer->taskException($serverName, 'Deployer\Task\NonFatalException', $exception->getMessage()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
12 |
|
$informer->endOnServer($serverName); |
|
50
|
12 |
|
} |
|
51
|
12 |
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
12 |
|
if ($success) { |
|
55
|
12 |
|
$informer->endTask(); |
|
56
|
12 |
|
} else { |
|
57
|
|
|
$informer->taskError(); |
|
58
|
|
|
} |
|
59
|
12 |
|
} |
|
60
|
12 |
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.