Adding support for beanstalkd-based workers.
This commit is contained in:
parent
07711a4e04
commit
3cbf9a1343
9 changed files with 699 additions and 351 deletions
|
|
@ -9,6 +9,10 @@
|
|||
|
||||
namespace PHPCI\Service;
|
||||
|
||||
use b8\Config;
|
||||
use Pheanstalk\Pheanstalk;
|
||||
use Pheanstalk\PheanstalkInterface;
|
||||
use PHPCI\BuildFactory;
|
||||
use PHPCI\Helper\Lang;
|
||||
use PHPCI\Model\Build;
|
||||
use PHPCI\Model\Project;
|
||||
|
|
@ -81,7 +85,13 @@ class BuildService
|
|||
$build->setExtra(json_encode($extra));
|
||||
}
|
||||
|
||||
return $this->buildStore->save($build);
|
||||
$build = $this->buildStore->save($build);
|
||||
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build->sendStatusPostback();
|
||||
$this->addBuildToQueue($build);
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -117,4 +127,31 @@ class BuildService
|
|||
$build->removeBuildDirectory();
|
||||
return $this->buildStore->delete($build);
|
||||
}
|
||||
|
||||
|
||||
public function addBuildToQueue(Build $build)
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
|
||||
$settings = $config->get('phpci.worker', []);
|
||||
|
||||
if (!empty($settings['host']) && !empty($settings['queue'])) {
|
||||
$jobData = array(
|
||||
'build_id' => $build->getId(),
|
||||
);
|
||||
|
||||
if ($config->get('using_custom_file')) {
|
||||
$jobData['config'] = $config->getArray();
|
||||
}
|
||||
|
||||
$pheanstalk = new Pheanstalk($settings['host']);
|
||||
$pheanstalk->useTube($settings['queue']);
|
||||
$pheanstalk->put(
|
||||
json_encode($jobData),
|
||||
PheanstalkInterface::DEFAULT_PRIORITY,
|
||||
PheanstalkInterface::DEFAULT_DELAY,
|
||||
$config->get('phpci.worker.job_timeout', 600)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue