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\Server\Local; |
13
|
|
|
use Deployer\Task\Context; |
14
|
|
|
use Deployer\Exception\NonFatalException; |
15
|
|
|
|
16
|
|
|
class SeriesExecutor implements ExecutorInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
10 |
|
public function run($tasks, $servers, $environments, $input, $output) |
22
|
|
|
{ |
23
|
10 |
|
$output = new OutputWatcher($output); |
24
|
10 |
|
$informer = new Informer($output); |
25
|
10 |
|
$localhost = new Local(); |
26
|
10 |
|
$localEnv = new Environment(); |
27
|
|
|
|
28
|
10 |
|
foreach ($tasks as $task) { |
29
|
10 |
|
$success = true; |
30
|
10 |
|
$informer->startTask($task->getName()); |
31
|
|
|
|
32
|
10 |
|
if ($task->isOnce()) { |
33
|
1 |
|
$task->run(new Context($localhost, $localEnv, $input, $output)); |
34
|
1 |
|
} else { |
35
|
10 |
|
foreach ($servers as $serverName => $server) { |
36
|
10 |
|
if ($task->isOnServer($serverName)) { |
37
|
10 |
|
$env = isset($environments[$serverName]) ? $environments[$serverName] : $environments[$serverName] = new Environment(); |
38
|
|
|
|
39
|
|
|
try { |
40
|
10 |
|
$task->run(new Context($server, $env, $input, $output)); |
41
|
10 |
|
} catch (NonFatalException $exception) { |
42
|
|
|
$success = false; |
43
|
|
|
$informer->taskException($serverName, 'Deployer\Exception\NonFatalException', $exception->getMessage()); |
44
|
|
|
} |
45
|
|
|
|
46
|
10 |
|
$informer->endOnServer($serverName); |
47
|
10 |
|
} |
48
|
10 |
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
10 |
|
if ($success) { |
52
|
10 |
|
$informer->endTask(); |
53
|
10 |
|
} else { |
54
|
|
|
$informer->taskError(); |
55
|
|
|
} |
56
|
10 |
|
} |
57
|
10 |
|
} |
58
|
|
|
} |
59
|
|
|
|