babymarkt / cron-bundle
一个简单的 Symfony cron bundle,用于编辑系统 crontab。
v2.0.2
2023-02-01 10:45 UTC
Requires
- php: >=7.4
- symfony/console: ^4.4 || ^5.4 || ^6.0
- symfony/framework-bundle: ^4.4 || ^5.4 || ^6.0
- symfony/yaml: ^4.4 || ^5.4 || ^6.0
Requires (Dev)
- mikey179/vfsstream: ~v1.6
- phpunit/phpunit: ^9.5.10
- symfony/test-pack: ^1.0
README
一个小型bundle,用于管理系统crontab中的cron条目。
安装
您需要通过composer要求此库
composer require babymarkt/cron-bundle
如果您正在使用 Symfony Flex,以下操作将自动执行。否则,您必须手动在 bundles.php
上启用此bundle
// config/bundles.php return [ // ... Babymarkt\Symfony\CronBundle\BabymarktCronBundle::class => ['all' => true], ];
配置
让我们从运行每分钟一个作业的最小配置开始
babymarkt_cron: cronjobs: my_job: 'my:symfony:command'
通过命令 bin/console babymarkt-cron:sync --env=prod
同步cron作业后,以下条目将在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 ###
有关CRON的更多信息,请参阅维基百科上的CRON表达式。
示例
每天凌晨3:30执行的作业
babymarkt_cron: cronjobs: my_job: command: 'my:symfony:command' minutes: 30 hours: 3
每周二在凌晨1:00至4:00之间每10分钟执行的作业
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>>' #...
命令
babymarkt-cron:drop
从crontab中删除所有整个cron作业块,不考虑配置的cron作业。
babymarkt-cron:dump
生成可能安装到crontab的cron条目,并在控制台上显示。
babymarkt-cron:report
显示有关配置cron作业执行的报告。此功能需要DoctrineBundle。
babymarkt-cron:sync
将配置的cron作业与crontab同步。只有相关的cron块将受到影响。
贡献
欢迎在GitHub上提交bug报告和pull请求 https://github.com/Baby-Markt/cron-bundle。
许可证
此bundle作为开源软件提供,受MIT许可证条款约束。