Cron integration for symfony.
Installing this bundle can be done through these simple steps:
- Add the bundle to your project as a composer dependency: With symfony Flex :
composer config extra.symfony.allow-contrib true
composer require nicoren/cron-bundle
without symfony Flex :
composer require nicoren/cron-bundle
- Add the bundle to your application kernel : If you don't use Symfony flex
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Nicoren\CronBundle\CronCronBundle(),
];
// ...
}
- Update your DB schema
3.1. ( doctrine ORM)
bin/console make:migration
bin/console doctrine:migrations:migrate
3.2. ( doctrine odm)
doctrine:mongodb:schema:update
- Configuration Overview: edit or create file config/packages/nicoren_cron.yaml
# config/packages/nicoren_cron.yaml
nicoren_cron:
db_driver: mongodb # other valid values are 'mongodb' and 'couchdb'
job_class: Nicoren\CronBundle\Model\Job
timezone: "Europe/Paris"
- To run your cron jobs automatically, add the following line to your (or whomever's) crontab:
* * * * * /path/to/symfony/install/app/console cron:run 1>> /dev/null 2>&1
bin/console cron:job:list
Show a list of all jobs.
bin/console cron:job:create
Create a new job.
bin/console cron:job:delete _jobId_
Delete a job. For your own protection, the job must be disabled first.
bin/console cron:job:enable _jobId_
Enable a job.
bin/console cron:job:disable _jobId_
Disable a job.
bin/console cron:run
which we borrowed from Symfony. Make sure to check out php-cs-fixer as this will help you a lot.
Please note that--force
forces the job to be executed (even if disabled) based on the job schedule
PHP 7.3 or above
Nicolas RENAULT - nicoren44@gmail.com
CronBundle is licensed under the MIT license.