Renamed app config worker section to queue + removed max_jobs option (use supervisord)
This commit is contained in:
parent
b5e96aa94c
commit
0ca5c8de51
5 changed files with 15 additions and 46 deletions
|
|
@ -14,9 +14,10 @@ php-censor:
|
|||
email_settings:
|
||||
from_address: 'no-reply@php-censor.local'
|
||||
smtp_address:
|
||||
worker:
|
||||
host: localhost
|
||||
queue: php-censor-queue
|
||||
queue:
|
||||
host: localhost
|
||||
name: php-censor-queue
|
||||
lifetime: 600
|
||||
github:
|
||||
token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
||||
comments:
|
||||
|
|
|
|||
|
|
@ -244,8 +244,8 @@ class InstallCommand extends Command
|
|||
$config['language'] = 'en';
|
||||
$config['per_page'] = 10;
|
||||
|
||||
$config['url'] = $url;
|
||||
$config['worker'] = $this->getQueueInformation($input, $output, $helper);
|
||||
$config['url'] = $url;
|
||||
$config['queue'] = $this->getQueueInformation($input, $output, $helper);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
|
@ -278,9 +278,9 @@ class InstallCommand extends Command
|
|||
$rtn['host'] = $helper->ask($input, $output, $questionQueue);
|
||||
}
|
||||
|
||||
if (!$rtn['queue'] = $input->getOption('queue-name')) {
|
||||
if (!$rtn['name'] = $input->getOption('queue-name')) {
|
||||
$questionName = new Question('Enter the queue (tube) name to use [php-censor-queue]: ', 'php-censor-queue');
|
||||
$rtn['queue'] = $helper->ask($input, $output, $questionName);
|
||||
$rtn['name'] = $helper->ask($input, $output, $questionName);
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
|
|
|
|||
|
|
@ -73,16 +73,15 @@ class WorkerCommand extends Command
|
|||
define('DEBUG_MODE', true);
|
||||
}
|
||||
|
||||
$config = Config::getInstance()->get('php-censor.worker', []);
|
||||
$config = Config::getInstance()->get('php-censor.queue', []);
|
||||
|
||||
if (empty($config['host']) || empty($config['queue'])) {
|
||||
if (empty($config['host']) || empty($config['name'])) {
|
||||
$error = 'The worker is not configured. You must set a host and queue in your config.yml file.';
|
||||
throw new \Exception($error);
|
||||
}
|
||||
|
||||
$worker = new BuildWorker($config['host'], $config['queue']);
|
||||
$worker = new BuildWorker($config['host'], $config['name']);
|
||||
$worker->setLogger($this->logger);
|
||||
$worker->setMaxJobs(Config::getInstance()->get('php-censor.worker.max_jobs', -1));
|
||||
$worker->startWorker();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,9 +160,9 @@ class BuildService
|
|||
}
|
||||
|
||||
$config = Config::getInstance();
|
||||
$settings = $config->get('php-censor.worker', []);
|
||||
$settings = $config->get('php-censor.queue', []);
|
||||
|
||||
if (!empty($settings['host']) && !empty($settings['queue'])) {
|
||||
if (!empty($settings['host']) && !empty($settings['name'])) {
|
||||
try {
|
||||
$jobData = [
|
||||
'type' => 'php-censor.build',
|
||||
|
|
@ -174,12 +174,12 @@ class BuildService
|
|||
}
|
||||
|
||||
$pheanstalk = new Pheanstalk($settings['host']);
|
||||
$pheanstalk->useTube($settings['queue']);
|
||||
$pheanstalk->useTube($settings['name']);
|
||||
$pheanstalk->put(
|
||||
json_encode($jobData),
|
||||
PheanstalkInterface::DEFAULT_PRIORITY,
|
||||
PheanstalkInterface::DEFAULT_DELAY,
|
||||
$config->get('php-censor.worker.job_timeout', 600)
|
||||
$config->get('php-censor.queue.lifetime', 600)
|
||||
);
|
||||
} catch (\Exception $ex) {
|
||||
$this->queueError = true;
|
||||
|
|
|
|||
|
|
@ -25,13 +25,6 @@ class BuildWorker
|
|||
*/
|
||||
protected $run = true;
|
||||
|
||||
/**
|
||||
* The maximum number of jobs this worker should run before exiting.
|
||||
* Use -1 for no limit.
|
||||
* @var int
|
||||
*/
|
||||
protected $maxJobs = -1;
|
||||
|
||||
/**
|
||||
* The logger for builds to use.
|
||||
* @var \Monolog\Logger
|
||||
|
|
@ -71,14 +64,6 @@ class BuildWorker
|
|||
$this->pheanstalk = new Pheanstalk($this->host);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $maxJobs
|
||||
*/
|
||||
public function setMaxJobs($maxJobs = -1)
|
||||
{
|
||||
$this->maxJobs = $maxJobs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Logger $logger
|
||||
*/
|
||||
|
|
@ -100,8 +85,6 @@ class BuildWorker
|
|||
// Get a job from the queue:
|
||||
$job = $this->pheanstalk->reserve();
|
||||
|
||||
$this->checkJobLimit();
|
||||
|
||||
// Get the job data and run the job:
|
||||
$jobData = json_decode($job->getData(), true);
|
||||
|
||||
|
|
@ -169,20 +152,6 @@ class BuildWorker
|
|||
$this->run = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this worker has done the amount of jobs it is allowed to do, and if so tells it to stop
|
||||
* after this job completes.
|
||||
*/
|
||||
protected function checkJobLimit()
|
||||
{
|
||||
// Make sure we don't run more than maxJobs jobs on this worker:
|
||||
$this->totalJobs++;
|
||||
|
||||
if ($this->maxJobs != -1 && $this->maxJobs <= $this->totalJobs) {
|
||||
$this->stopWorker();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the job received is actually from PHPCI, and has a valid type.
|
||||
* @param Job $job
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue