forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkerCommand.php
More file actions
80 lines (71 loc) · 2.05 KB
/
Copy pathWorkerCommand.php
File metadata and controls
80 lines (71 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace PHPCensor\Command;
use Monolog\Logger;
use PHPCensor\Config;
use PHPCensor\Service\BuildService;
use PHPCensor\Worker\BuildWorker;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Worker Command - Starts the BuildWorker, which pulls jobs from beanstalkd
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class WorkerCommand extends LoggingCommand
{
/**
* @var BuildService
*/
protected $buildService;
/**
* @param Logger $logger
* @param BuildService $buildService
* @param string $name
*/
public function __construct(
Logger $logger,
BuildService $buildService,
$name = null
)
{
parent::__construct($logger, $name);
$this->buildService = $buildService;
}
protected function configure()
{
$this
->setName('php-censor:worker')
->addOption(
'periodical-work',
'p',
InputOption::VALUE_NONE,
'Allow worker run periodical work'
)
->setDescription('Runs the PHP Censor build worker.');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$config = Config::getInstance()->get('php-censor.queue', []);
if (empty($config['host']) || empty($config['name'])) {
throw new \RuntimeException(
'The worker is not configured. You must set a host and queue in your config.yml file.'
);
}
(new BuildWorker(
$this->logger,
$this->buildService,
$config['host'],
$config['name'],
($input->hasOption('periodical-work') && $input->getOption('periodical-work'))
))
->startWorker();
}
}