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\Console; |
9
|
|
|
|
10
|
|
|
use Deployer\Collection\PersistentCollection; |
11
|
|
|
use Deployer\Deployer; |
12
|
|
|
use Deployer\Exception\Exception; |
13
|
|
|
use Deployer\Exception\GracefulShutdownException; |
14
|
|
|
use Deployer\Exception\NonFatalException; |
15
|
|
|
use Deployer\Task\Context; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption as Option; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
class WorkerCommand extends MainCommand |
22
|
|
|
{ |
23
|
6 |
|
public function __construct(Deployer $deployer) |
24
|
|
|
{ |
25
|
6 |
|
parent::__construct('worker', null, $deployer); |
26
|
6 |
|
$this->setHidden(true); |
27
|
6 |
|
} |
28
|
|
|
|
29
|
6 |
|
protected function configure() |
30
|
|
|
{ |
31
|
6 |
|
$this->addArgument('worker-task', InputArgument::REQUIRED); |
32
|
6 |
|
$this->addArgument('worker-host', InputArgument::REQUIRED); |
33
|
6 |
|
$this->addArgument('config-directory', InputArgument::REQUIRED); |
34
|
6 |
|
$this->addArgument('original-task', InputArgument::REQUIRED); |
35
|
6 |
|
$this->addOption('decorated', null, Option::VALUE_NONE); |
36
|
6 |
|
parent::configure(); |
37
|
6 |
|
} |
38
|
|
|
|
39
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
1 |
|
$this->deployer->input = $input; |
42
|
1 |
|
$this->deployer->output = $output; |
43
|
|
|
|
44
|
1 |
|
$output->setDecorated($input->getOption('decorated')); |
45
|
1 |
|
if (!$output->isDecorated() && !defined('NO_ANSI')) { |
46
|
|
|
define('NO_ANSI', 'true'); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
$host = $this->deployer->hosts->get($input->getArgument('worker-host')); |
|
|
|
|
50
|
1 |
|
$task = $this->deployer->tasks->get($input->getArgument('worker-task')); |
51
|
|
|
|
52
|
1 |
|
$this->deployer->config->set('config_directory', $input->getArgument('config-directory')); |
53
|
1 |
|
$host->getConfig()->load(); |
54
|
|
|
|
55
|
1 |
|
foreach ($host->getConfig() as $name => $value) { |
56
|
|
|
$this->deployer->config->set($name, $value); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
try { |
60
|
1 |
|
Exception::setTaskSourceLocation($task->getSourceLocation()); |
61
|
1 |
|
$task->run(new Context($host, $input, $output)); |
62
|
|
|
|
63
|
1 |
|
$this->deployer->messenger->endOnHost($host); |
64
|
1 |
|
$host->getConfig()->save(); |
65
|
1 |
|
return 0; |
66
|
|
|
} catch (GracefulShutdownException $e) { |
67
|
|
|
$this->deployer->messenger->renderException($e, $host); |
68
|
|
|
return GracefulShutdownException::EXIT_CODE; |
69
|
|
|
} catch (\Throwable $e) { |
70
|
|
|
$this->deployer->messenger->renderException($e, $host); |
71
|
|
|
return 255; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.