mtamazlicaru / cron-bundle
With the CronBundle you can configure cron jobs in configuration files
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 5 671
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 7
Type:symfony-bundle
Requires
- php: >=5.3.2
- mtdowling/cron-expression: 1.0.*
- symfony/framework-bundle: ~2.1
Requires (Dev)
- monolog/monolog: ~1.7.0
- phpunit/phpunit: ~4.3
- symfony/console: ~2.1
- symfony/options-resolver: ~2.1
- symfony/process: ~2.1
This package is not auto-updated.
Last update: 2020-04-15 02:48:36 UTC
README
Symfony2 Bundle for setting up cron jobs via configuration.
Installation
Prerequisites
This bundle requires Symfony 3+, as it must be installed with composer.
Download SbkCronBundle with composer
Add the following to your project composer.json
:
{ "require": { "mtamazlicaru/cron-bundle": "dev-master" } }
Now install it with this command:
$ php composer.phar update mtamazlicaru/cron-bundle
The bundle should be downloaded to the vendor
directory.
Enable the bundle
You need to add the bundle in app/AppKernel.php
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Sbk\Bundle\CronBundle\SbkCronBundle(), ); }
Import Services
The CronBundle depends on certain services, so you need to import the service configuration in app/config/config.yml
imports:
# ...
- { resource: @SbkCronBundle/Resources/config/services.yml }
Now you should be able to use the Cron Manager.
Usage
Configuring Tasks
Tasks can be configured in app/config/config(_prod).yml
.
sbk_cron:
tasks:
clearcache:
command: "cache:clear --env=prod"
expression: "0 0 * * *"
listoutput:
bin: "ls"
script: ""
command: "-l > /var/log/listoutput.log"
expression: "@daily"
Each entry in sbk_cron.tasks
represents a task.
command
The command to execute. By default the cron manager will prepend %kernel.root_dir%/../bin/console
before the command name, so configuring console commands is easy. You can run every command you want with this bundle, read on how to do so.
expression
The cron expression, any valid expression that you would enter in a cron table.
bin
The binary which will execute the command (php
by default, you could enter ''
to omit the bin in the execution command)
script
The script that will be called (%kernel.root_dir%/../bin/console
by default).
Runnign the master cron job
Even if you can configure all cron jobs with this bundle, you need to add one line to the crontab manually, the cron:run
command.
* * * * * php /var/www/bin/console cron:run
This will execute the cron manager every minute.
The manager will check which tasks need to be executed and will create background processes for every due task.