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::execute()   B

Complexity

Conditions 6
Paths 39

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 19
nc 39
nop 2
dl 0
loc 31
ccs 0
cts 25
cp 0
crap 42
rs 8.439
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