This bundle is designed around the idea to schedule the commands within the project and therefore under VCS control.
Use this version with at least symfony 4
- Add the bundle to your project as a composer dependency:
// composer.json
{
// ...
require: {
// ...
"comparon/megacron": "dev-master"
},
// ...
"repositories": [
// ...
{
"type": "vcs",
"url": "https://github.com/Comparon/Megacron.git"
}
]
}
- Update your composer installation:
composer update
- Add the bundle to bundles.php:
// config/bundles.php
return [
// ...
Comparon\MegacronBundle\ComparonMegacronBundle::class => [ 'all' => true],
];
- Add command to services.yaml
Comparon\MegacronBundle\Command\SchedulerCommand:
arguments:
$projectDir: '%kernel.project_dir%'
tags:
- 'console.command'
All you have to do is to implement the TaskInterface (and therefore the method getTaskConfigurations()) in your Command:
class DemoCommand extends ContainerAwareCommand implements TaskInterface
{
protected function configure()
{
// ...
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// ...
}
/**
* @return TaskConfiguration[]
*/
public function getTaskConfigurations()
{
$configs = [];
$configMonday = new TaskConfiguration();
$configMonday->setCronExpression('* * * * 1');
$configs[] = $configMonday;
$configTuesday = new TaskConfiguration();
$configTuesday
->setCronExpression('0 * * * 2')
->setWithOverlapping(false)
;
$configs[] = $configTuesday;
return $configs;
}
}
To facilitate this, you can create a cron job on your system like this:
* * * * * <path to console> comparon:scheduler:run