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\Deployer; |
||
11 | use Deployer\Executor\Worker; |
||
12 | use Symfony\Component\Console\Input\InputArgument; |
||
13 | use Symfony\Component\Console\Input\InputInterface; |
||
14 | use Symfony\Component\Console\Input\InputOption as Option; |
||
15 | use Symfony\Component\Console\Output\OutputInterface; |
||
16 | |||
17 | class WorkerCommand extends MainCommand |
||
18 | { |
||
19 | 12 | public function __construct(Deployer $deployer) |
|
20 | { |
||
21 | 12 | parent::__construct('worker', null, $deployer); |
|
22 | 12 | $this->setHidden(true); |
|
23 | 12 | } |
|
24 | |||
25 | 12 | protected function configure() |
|
26 | { |
||
27 | 12 | $this->addArgument('worker-task', InputArgument::REQUIRED); |
|
28 | 12 | $this->addArgument('worker-host', InputArgument::REQUIRED); |
|
29 | 12 | $this->addArgument('master-port', InputArgument::REQUIRED); |
|
30 | 12 | $this->addArgument('original-task', InputArgument::REQUIRED); // added as stringing $input adds own args |
|
31 | 12 | $this->addOption('decorated', null, Option::VALUE_NONE); |
|
32 | 12 | parent::configure(); |
|
33 | 12 | } |
|
34 | |||
35 | protected function execute(InputInterface $input, OutputInterface $output) |
||
36 | { |
||
37 | $this->deployer->input = $input; |
||
38 | $this->deployer->output = $output; |
||
39 | |||
40 | $output->setDecorated($input->getOption('decorated')); |
||
41 | if (!$output->isDecorated() && !defined('NO_ANSI')) { |
||
42 | define('NO_ANSI', 'true'); |
||
43 | } |
||
44 | |||
45 | $this->deployer->config->set('master_url', 'http://localhost:' . $input->getArgument('master-port')); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
46 | |||
47 | $task = $this->deployer->tasks->get($input->getArgument('worker-task')); |
||
48 | $host = $this->deployer->hosts->get($input->getArgument('worker-host')); |
||
49 | $host->config()->load(); |
||
50 | |||
51 | // TODO: Maybe relevant to leave this code. Was here when loading from config file was. |
||
52 | // foreach ($host->getConfig() as $name => $value) { |
||
53 | // $this->deployer->config->set($name, $value); |
||
54 | // } |
||
55 | $worker = new Worker($this->deployer); |
||
56 | $exitCode = $worker->execute($task, $host); |
||
57 | |||
58 | $host->config()->save(); |
||
59 | return $exitCode; |
||
60 | } |
||
61 | } |
||
62 |