Permalink
Browse files

Added implementation of periodical builds in Worker and cronjob with

rich configuration (app/periodical.yml config).
  • Loading branch information...
corpsee committed Oct 13, 2018
1 parent 31ed99d commit f9275cd8c08fad9f0d12c766dc68cd98d99aaee5
@@ -1,6 +1,11 @@
/vendor
/composer.phar
/vendor
/public/assets/vendor
/app/config.yml
/app/periodical.yml
/runtime/*.log
/runtime/builds
@@ -12,8 +17,5 @@
/runtime/status_cache
!/runtime/status_cache/.gitkeep
/app/config.yml
/public/assets/vendor
/public/artifacts
!/public/artifacts/.gitkeep
@@ -27,6 +27,9 @@ Using PHP Censor
* [Injecting variables into messages](interpolation.md)
* [Project Status Images and Status Page](status.md)
* [Build environments](environments.md)
* [Periodical builds](periodical_builds.md)
* [Console commands](commands.md)
* [CCMenu/CCTray integration](ccmenu.md)
Plugins
-------
@@ -0,0 +1,4 @@
CCMenu/CCTray integration
=========================
Use URL: `http://php-censor.local/build-status/ccxml/<project_id>`.
@@ -0,0 +1,11 @@
Console commands
================
* `php-censor:check-localizations` - Check localizations.
* `php-censor:create-admin` - Create an admin user
* `php-censor:create-build` - Create a build for a project
* `php-censor:install` - Install PHP Censor
* `php-censor:rebuild` - Re-runs the last run build.
* `php-censor:rebuild-queue` - Rebuilds the PHP Censor worker queue.
* `php-censor:run-builds` - Run all pending PHP Censor builds
* `php-censor:worker` - Runs the PHP Censor build worker.
@@ -0,0 +1,22 @@
Periodical builds
=================
You can create periodical builds for your projects. For starting use periodical builds you should create config
`app/periodical.yml` and run **one of the workers** with option `--periodical-work|-p`:
`./bin/console php-censor:worker -v --periodical-work` (With cronjob worker feature starts work automatically).
Periodical builds config example:
```yaml
projects:
1: # Project id
branches: # Branch list for periodical build
- master
- release-1.0
- release-2.0
interval: P1W # Interval to build project if no other builds (from webhook etc.).Used format of PHP DateInterval class. See: http://php.net/manual/ru/dateinterval.construct.php
12: # Another project id
branches:
- master
interval: PT12H
```
@@ -9,6 +9,8 @@
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore;
/**
* Re-runs the last run build.
@@ -62,11 +64,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$runner = new RunCommand($this->logger);
$runner->setMaxBuilds(1);
/** @var \PHPCensor\Store\BuildStore $store */
$store = Factory::getStore('Build');
$service = new BuildService($store);
/** @var BuildStore $buildStore */
$buildStore = Factory::getStore('Build');
$builds = $store->getLatestBuilds(null, 1);
/** @var ProjectStore $projectStore */
$projectStore = Factory::getStore('Project');
$service = new BuildService($buildStore, $projectStore);
$builds = $buildStore->getLatestBuilds(null, 1);
$lastBuild = array_shift($builds);
$service->createDuplicateBuild($lastBuild);
@@ -2,11 +2,13 @@
namespace PHPCensor\Command;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\Factory;
use Monolog\Logger;
use PHPCensor\BuildFactory;
use PHPCensor\Logging\OutputLogHandler;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\ProjectStore;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -55,12 +57,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
}
$store = Factory::getStore('Build');
$result = $store->getByStatus(0);
/** @var BuildStore $buildStore */
$buildStore = Factory::getStore('Build');
/** @var ProjectStore $projectStore */
$projectStore = Factory::getStore('Project');
$result = $buildStore->getByStatus(0);
$this->logger->addInfo(sprintf('Found %d builds', count($result['items'])));
$buildService = new BuildService($store);
$buildService = new BuildService($buildStore, $projectStore);
while (count($result['items'])) {
$build = array_shift($result['items']);
@@ -4,7 +4,9 @@
use Monolog\Logger;
use PHPCensor\Logging\BuildDBLogHandler;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use PHPCensor\Store\Factory;
@@ -19,11 +21,32 @@
*/
class RunCommand extends LoggingCommand
{
/**
* @var BuildService
*/
protected $buildService;
/**
* @var int
*/
protected $maxBuilds = 10;
/**
* @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
@@ -37,7 +60,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var BuildStore $buildStore */
$buildStore = Factory::getStore('Build');
$result = $buildStore->getByStatus(Build::STATUS_PENDING, $this->maxBuilds);
$this->buildService->createPeriodicalBuilds($this->logger);
$result = $buildStore->getByStatus(Build::STATUS_PENDING, $this->maxBuilds);
$this->logger->notice(
sprintf('Found %d pending builds', count($result['items']))

This file was deleted.

Oops, something went wrong.
@@ -2,9 +2,15 @@
namespace PHPCensor\Command;
use Monolog\Logger;
use PHPCensor\Config;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\Factory;
use PHPCensor\Store\ProjectStore;
use PHPCensor\Worker\BuildWorker;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -14,10 +20,37 @@
*/
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.');
}
@@ -38,7 +71,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
}
(new BuildWorker($this->logger, $config['host'], $config['name']))
(new BuildWorker(
$this->logger,
$this->buildService,
$config['host'],
$config['name'],
($input->hasOption('periodical-work') && $input->getOption('periodical-work'))
))
->startWorker();
}
}
Oops, something went wrong.

0 comments on commit f9275cd

Please sign in to comment.