-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b146b60
Showing
24 changed files
with
928 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
composer.lock | ||
composer.phar | ||
bin/ | ||
vendor/ | ||
/Tests/Fixtures/app/cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
|
||
env: | ||
- SYMFONY_VERSION="2.2.*" | ||
- SYMFONY_VERSION="2.3.*" | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar require symfony/framework-bundle:${SYMFONY_VERSION} | ||
- php composer.phar require symfony/console:${SYMFONY_VERSION} | ||
- php composer.phar install --dev | ||
|
||
script: bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace MyBuilder\Bundle\CronosBundle\Annotation; | ||
|
||
use Doctrine\Common\Annotations\Annotation; | ||
|
||
/** | ||
* Cron annotation which we can parse to generate a cron file | ||
* | ||
* @Annotation | ||
* @Target("CLASS") | ||
*/ | ||
class Cron extends Annotation | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $minute; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $hour; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $dayOfMonth; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $month; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $dayOfWeek; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $comment; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $logFile; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $errorFile; | ||
|
||
/** | ||
* If true add /dev/null. | ||
* | ||
* @var boolean | ||
*/ | ||
public $noLogs; | ||
|
||
/** | ||
* Which server should this cron job run on. | ||
* | ||
* @var string | ||
*/ | ||
public $server; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $params; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $executor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace MyBuilder\Bundle\CronosBundle\Command; | ||
|
||
use MyBuilder\Bundle\CronosBundle\Service\AnnotationCronExporter; | ||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class CommandBase extends ContainerAwareCommand | ||
{ | ||
/** | ||
* Configure the shared command options | ||
*/ | ||
protected function configureSharedOptions() | ||
{ | ||
$this | ||
->addOption('server', null, InputOption::VALUE_REQUIRED, 'Only include cron jobs for the specified server', AnnotationCronExporter::ALL_SERVERS); | ||
} | ||
|
||
/** | ||
* Configure cron export | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return mixed | ||
*/ | ||
protected function configureCronExport(InputInterface $input, OutputInterface $output) | ||
{ | ||
$serverName = $input->getOption('server'); | ||
$output->writeln(sprintf('Server <comment>%s</comment>', $serverName)); | ||
$cron = $this->exportCron($serverName); | ||
$output->writeln(sprintf('<Comment>Found %d lines<comment>', $cron->countLines())); | ||
|
||
return $cron; | ||
} | ||
|
||
private function exportCron($serverName) | ||
{ | ||
$commands = $this->getApplication()->all(); | ||
$exporter = $this->getContainer()->get('mybuilder.cronos_bundle.annotation_cron_exporter'); | ||
|
||
return $exporter->export($commands, $serverName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace MyBuilder\Bundle\CronosBundle\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Dump the cron file that would be produced from the cron annotations in this project. | ||
*/ | ||
class DumpCommand extends CommandBase | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('cronos:dump') | ||
->setDescription('Dump cron configuration'); | ||
|
||
$this->configureSharedOptions(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$cron = $this->configureCronExport($input, $output); | ||
|
||
$output->writeln('<info>We would have put the following in cron</info>'); | ||
$output->write($content = $cron->format()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace MyBuilder\Bundle\CronosBundle\Command; | ||
|
||
use MyBuilder\Cronos\Updater\CronUpdatingError; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ReplaceCommand extends CommandBase | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('cronos:replace') | ||
->setDescription('Replace the current content of your crontab with the cron annotations within this project'); | ||
|
||
$this->configureSharedOptions(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$cron = $this->configureCronExport($input, $output); | ||
|
||
$updater = $this->getContainer()->get('mybuilder.cronos_bundle.cron_process_updater'); | ||
try { | ||
$updater->updateWith($cron->format()); | ||
$output->writeln('<info>Cron successfully updated</info>'); | ||
} catch (CronUpdatingError $e) { | ||
$output->writeln(sprintf('<Comment>Cron cannot be updated - %s<comment>', $e->getMessage())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace MyBuilder\Bundle\CronosBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('my_builder_cronos'); | ||
|
||
$rootNode | ||
->children() | ||
->arrayNode('exporter') | ||
->children() | ||
->scalarNode('mailto')->example('cron@example.com')->end() | ||
->scalarNode('path')->example('/usr/local/bin::/usr/bin:/bin') ->end() | ||
->scalarNode('executor')->example('app/console') ->end() | ||
->scalarNode('shell')->example('/bin/sh') ->end() | ||
->end() | ||
->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace MyBuilder\Bundle\CronosBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
|
||
class MyBuilderCronosExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$config = $this->processConfiguration(new Configuration(), $configs); | ||
|
||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | ||
$loader->load('services.yml'); | ||
|
||
$exporterConfig = isset($config['exporter']) ? $config['exporter'] : array(); | ||
$container->setParameter('mybuilder.cronos_bundle.exporter_config', $exporterConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2013 MyBuilder Limited | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace MyBuilder\Bundle\CronosBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class MyBuilderCronosBundle extends Bundle {} |
Oops, something went wrong.