GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 99078a...9605c1 )
by Oanh
02:49
created

WorkerCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 19
rs 9.4285
cc 1
eloc 12
nc 1
nop 1
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\Console\Output\RemoteOutput;
11
use Deployer\Deployer;
12
use Deployer\Server\Environment;
13
use Deployer\Task\Context;
14
use Deployer\Task\NonFatalException;
15
use Pure\Client;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class WorkerCommand extends Command
22
{
23
    /**
24
     * @var Deployer
25
     */
26
    private $deployer;
27
28
    /**
29
     * @param Deployer $deployer
30
     */
31
    public function __construct(Deployer $deployer)
32
    {
33
        parent::__construct('worker');
34
        $this->setDescription('Deployer uses workers for parallel deployment.');
35
36
        $this->deployer = $deployer;
37
38
        $this->addOption(
39
            'master',
40
            null,
41
            InputOption::VALUE_REQUIRED
42
        );
43
44
        $this->addOption(
45
            'server',
46
            null,
47
            InputOption::VALUE_REQUIRED
48
        );
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $serverName = $input->getOption('server');
57
        list($host, $port) = explode(':', $input->getOption('master'));
58
        $pure = new Client($port, $host);
59
60
        try {
61
            $server = $this->deployer->servers->get($serverName);
62
            $environment = isset($this->deployer->environments[$serverName]) ? $this->deployer->environments[$serverName] : new Environment();
63
            $output = new RemoteOutput($output, $pure, $serverName);
64
65
            while ($pure->ping()) {
66
                // Get task to do
67
                $taskName = $pure->map('tasks_to_do')->get($serverName);
68
69
                if (null !== $taskName) {
70
                    $task = $this->deployer->tasks->get($taskName);
71
72
                    try {
73
                        $task->run(new Context($server, $environment, $input, $output));
74
                    } catch (NonFatalException $e) {
75
                        $pure->queue('exception')->push([$serverName, get_class($e), $e->getMessage()]);
76
                    }
77
78
                    $pure->map('tasks_to_do')->delete($serverName);
79
                }
80
            }
81
        } catch (\Exception $exception) {
82
            $pure->queue('exception')->push([$serverName, get_class($exception), $exception->getMessage()]);
83
        }
84
    }
85
}
86