diff --git a/app/config.example.yml b/app/config.example.yml index b0574a30..c7c05952 100644 --- a/app/config.example.yml +++ b/app/config.example.yml @@ -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: diff --git a/src/PHPCensor/Command/InstallCommand.php b/src/PHPCensor/Command/InstallCommand.php index e4b31f06..8bbfbbd3 100644 --- a/src/PHPCensor/Command/InstallCommand.php +++ b/src/PHPCensor/Command/InstallCommand.php @@ -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; diff --git a/src/PHPCensor/Command/WorkerCommand.php b/src/PHPCensor/Command/WorkerCommand.php index 323e8807..a211d63e 100644 --- a/src/PHPCensor/Command/WorkerCommand.php +++ b/src/PHPCensor/Command/WorkerCommand.php @@ -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(); } } diff --git a/src/PHPCensor/Service/BuildService.php b/src/PHPCensor/Service/BuildService.php index 2ac88557..aaf5a85b 100644 --- a/src/PHPCensor/Service/BuildService.php +++ b/src/PHPCensor/Service/BuildService.php @@ -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; diff --git a/src/PHPCensor/Worker/BuildWorker.php b/src/PHPCensor/Worker/BuildWorker.php index 515fb1b4..2302b3b2 100644 --- a/src/PHPCensor/Worker/BuildWorker.php +++ b/src/PHPCensor/Worker/BuildWorker.php @@ -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