Блог /
Пост 1 cron-bundle Installation
logist/cron-bundle

Installation
composer require logist/cron-bundle
After installation composer run script LogistCronBundle\Composer\CrontabHandler\ScriptHandler::updateCrontabCommands which automaticaly update all crontab commands from bundle configuration
AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new LogistCronBundle\LogistCronBundle(),
//...
);
}
Configuration
# app/config/bundles/cron-bundle.yml
logist_cron:
tender_automation:
# run task schedule expression
spec: '0 * * * *'
cmd: 'command relative path'
new_automation:
# run task schedule expression
spec: '0 * * * *'
cmd: 'command relative path'
# log file relative path in app/logs directory
log: 'cron/cron_bundle.log'
logrotate:
# log file rotation schedule expression
spec: '* * * * *'
config:
# how many file can be rotated
rotate: 4
# max filesize for log rotation files
size: 1K
# max log rotation files age
maxage: 1
Usage
Add command
php app/console logist:cron:crontab add --cmd "command full path" --spec "0 * * * *" --log "log file relative path"
- cmd - full path to crontab command
- spec - time interval
- log - relative path to cron log
Remove command
php app/console logist:cron:crontab remove --cmd "command full path"
- cmd - full path to crontab command
Commands list
To show registered in bundle and added to crontab commands list execute command:
php app/console logist:cron:crontab list
Log prerotate
Dispatch log prerotate event to event dispatcher
php app/console logist:cron:crontab prerotate
Log postrotate
Dispatch log postrotate event to event dispatcher
php app/console logist:cron:crontab postrotate
Validate configuration
To check all configured task validation and syncronization with crontab list execute command:
php app/console logist:cron:cron:config validate
Update commands list
Update all commands from bundle configuration in app/config/bundles/cron-bundle.yml To automaticaly update crontab command from configuration commands list execute command:
php app/console logist:cron:cron:config update -v -n
- -v - verbose level
- -n - no-interaction
Before update script run backup command and clear command.
Backup command
To create backup from crontab execute:
php app/console logist:cron:cron:config backup
To restore backup execute:
php app/console logist:cron:cron:config bakcup -r -f filename.bak
- -r - restore flag
- -f - backup file name. If empty, script restore last backup file
To show backup files list exceude command with limit option:
php app/console logist:cron:cron:config backup -l 10
Show last 10 backup files.
Clear command
All command automaticaly added to crontab by update command wrap in comments #GENERATED_CRONTAB_SCRIPT … #GENERATED_CRONTAB_SCRIPT_END Clear command remove all lines between this comments from crontab:
php app/console logist:cron:cron:config clear
Show only configured commands list
Command display only defined in configuration commands from crontab
php app/console logist:cron:config list
Show task detail
Pretty formatted information about crontab task could be displayed by executing command:
php app/console logist:cron:config show -t
- -t, —task: required option, whitch task detail information should be displayed
- -a, —all: if isset, then log and logrotate information will be displayed. Last log record willbe displayed if exists.
- -l, —limit: set integer value how match log record you want to display
Run task
To run manualy one of configured task execute command:
php app/console logist:cron:config run -t
- -t, —task: option, whitch task will be run. Every run will be logged, even if task is not defined or does not exists.