A small bundle to manage cron entries in system crontab.
You need to require this library through composer:
composer require babymarkt/cron-bundle
If you are using Symfony Flex, the following will happen automatically. Otherwise,
you have to enable the bundle on the bundles.php
manually:
// config/bundles.php
return [
// ...
Babymarkt\Symfony\CronBundle\BabymarktCronBundle::class => ['all' => true],
];
Let's start with a minimal setup to run a job every minute:
babymarkt_cron:
cronjobs:
my_job: 'my:symfony:command'
After syncing the cronjobs with the command bin/console babymarkt-cron:sync --env=prod
,
following entry are created in the crontab:
###> /your/project-dir:prod ###
# job 'my_job' (no description)
* * * * * cd /your/project-dir; php bin/console --env=prod my:symfony:command 2>&1 1>>/dev/null
###< /your/project-dir:prod ###
To learn more about CRON see CRON expression on Wikipedia.
A job running every day at 3:30 AM
babymarkt_cron:
cronjobs:
my_job:
command: 'my:symfony:command'
minutes: 30
hours: 3
A job running every Tuesday every 10 minutes between 1:00 and 4:00 AM
babymarkt_cron:
cronjobs:
my_job:
command: 'my:symfony:command'
minutes: '*/10' # or '0,10,20,30,40,50'
hours: '1-4'
weekdays: 3 # Tuesday (SUN-SAT: 0-6)
babymarkt_cron:
options:
# This ID is used to identify the job block in the crontab. If not defined,
# it is automatically generated from the project directory and the environment.
id: ~
# The script to run the commands.
script: 'bin/console'
# The working directory. Defaults to %kernel.project_dir%.
working_dir: ~
# Specifies globally where the output should be written to.
output:
file: '/dev/null'
append: true
# Crontab options
crontab:
# Crontab executable.
bin: 'crontab'
# Path to store the temporary crontab content. Defaults to the system temp dir.
tmpPath: ~
# The user to execute the crontab.
user: ~
# Defines whether sudo is used or not.
sudo: false
cronjobs:
# The name of the job definition
your-first-job-name:
# Definition of the execution time
# See https://en.wikipedia.org/wiki/Cron#CRON_expression
minutes: *
hours: *
days: *
months: *
weekdays: *
# The Symfony command to execute.
command: ~ # required
# If TRUE, the command isn't executed.
disabled: false
# Overwrites the global output settings.
output:
file: ~
append: ~
# Command arguments and options.
arguments:
- '<<your-first-argument>>'
- '<<your-second-argument>>'
#...
Drops all the whole cronjobs block from crontab not considering the configured cronjobs.
Generates the cron entries which may be installed to crontab and shows it on console.
Show some reports about the execution of the configured cronjobs. This features required the DoctrineBundle.
Syncs the configured cronjobs with the crontab. Only the related cron block will be affected.
Bug reports and pull requests are welcome on GitHub at https://github.com/Baby-Markt/cron-bundle.
The bundle is available as open source under the terms of the MIT License.