Verify that jobs actually come from PHPCI

This commit is contained in:
Dan Cryer 2015-10-06 11:38:09 +01:00
parent de1c058f83
commit 7e2fee9504
2 changed files with 15 additions and 0 deletions

View file

@ -152,6 +152,7 @@ class BuildService
if (!empty($settings['host']) && !empty($settings['queue'])) {
$jobData = array(
'type' => 'phpci.build',
'build_id' => $build->getId(),
);

View file

@ -82,6 +82,7 @@ class BuildWorker
{
$pheanstalk = new Pheanstalk($this->host);
$pheanstalk->watch($this->queue);
$pheanstalk->ignore('default');
$buildStore = Factory::getStore('Build');
$jobs = 0;
@ -99,6 +100,19 @@ class BuildWorker
// Get the job data and run the job:
$jobData = json_decode($job->getData(), true);
if (empty($jobData) || !is_array($jobData)) {
// Probably not from PHPCI.
$pheanstalk->release($job);
continue;
}
if (!array_key_exists('type', $jobData) || $jobData['type'] !== 'phpci.build') {
// Probably not from PHPCI.
$pheanstalk->release($job);
continue;
}
$this->logger->addInfo('Received build #'.$jobData['build_id'].' from Beanstalkd');
// If the job comes with config data, reset our config and database connections