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   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 1
B execute() 0 31 6
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