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.
Passed
Pull Request — master (#1061)
by Maxim
04:23 queued 01:35
created

WorkerCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 20
ccs 0
cts 17
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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\Exception\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->setHidden(true);
35
        $this->setDescription('Deployer uses workers for parallel deployment');
36
37
        $this->deployer = $deployer;
38
39
        $this->addOption(
40
            'master',
41
            null,
42
            InputOption::VALUE_REQUIRED
43
        );
44
45
        $this->addOption(
46
            'server',
47
            null,
48
            InputOption::VALUE_REQUIRED
49
        );
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $serverName = $input->getOption('server');
58
        list($host, $port) = explode(':', $input->getOption('master'));
59
        $pure = new Client($port, $host);
60
61
        try {
62
            $server = $this->deployer->servers->get($serverName);
63
            $environment = isset($this->deployer->environments[$serverName]) ? $this->deployer->environments[$serverName] : new Environment();
64
            $output = new RemoteOutput($output, $pure, $serverName);
65
66
            while ($pure->ping()) {
67
                // Get task to do
68
                $taskName = $pure->map('tasks_to_do')->get($serverName);
69
70
                if (null !== $taskName) {
71
                    $task = $this->deployer->tasks->get($taskName);
72
73
                    try {
74
                        $task->run(new Context($server, $environment, $input, $output));
75
                    } catch (NonFatalException $e) {
76
                        $pure->queue('exception')->push([$serverName, get_class($e), $e->getMessage()]);
77
                    }
78
79
                    $pure->map('tasks_to_do')->delete($serverName);
80
                }
81
            }
82
        } catch (\Exception $exception) {
83
            $pure->queue('exception')->push([$serverName, get_class($exception), $exception->getMessage()]);
84
        }
85
    }
86
}
87