mintware-de/native-cron-bundle
Composer 安装命令:
composer require mintware-de/native-cron-bundle
包简介
A Symfony bundle for mintware-de/native-cron
README 文档
README
This package provides a Symfony Bundle for the mintware-de/native-cron package.
The main purpose is easily managing cron jobs for your application.
Installation
composer require mintware-de/native-cron-bundle
Since cron jobs stored differently based on the operating system, you've to set the CrontabFileLocatorInterface
in your service definition.
This bundle will only work with drop-in crontab files. So make sure that the implementation supports that feature.
services: MintwareDe\NativeCron\Filesystem\CrontabFileLocatorInterface: class: MintwareDe\NativeCron\Filesystem\DebianCrontabFileLocator
Requirements
- PHP 8.1+
- Symfony 6.1
Usage
Mark Commands as Cronjobs
After installing the bundle you can use the #[CronJob(...)] annotation (MintwareDe\NativeCronBundle\Attribute\CronJob)
on your console commands.
This annotation accepts 2-5 arguments:
#[CronJob(
name: 'my_cron_job', // This is the name of the cron job. It is used to trigger the command
// using the mw:cron:run command
# .---------------- minute (0 - 59)
# | .-------------- hour (0 - 23)
# | | .------------ day of month (1 - 31)
# | | | .---------- month (1 - 12)
# | | | | .-------- day of week (0 - 6; Sunday=0)
# | | | | |
executeAt: '* * * * *', // This is the execution time definition. The format is identical to the crontab file.
user: 'root', // The user that will be used to run the command. Optional, default = root
arguments: [ // The arguments that are passed to your command. See also here (ArrayInput): https://symfony.com/doc/current/console/calling_commands.html
'name' => 'Foo', // InputArgument
'--yell' => true, // Input option
],
)]
#[AsCommand(...)]
class MyCommand extends \Symfony\Component\Console\Command\Command {
// ...
}
List / Install / Uninstall
You can use the Symfony console to list, install and uninstall the cron jobs. Remember: Install and uninstall may require higher user privileges! (su root / sudo etc.)
List
$ php bin/console mw:cron:list Cron jobs ========= -------------- ------------ ---------------- ------------ Name Execute At Arguments Command -------------- ------------ ---------------- ------------ my_cron_job * * * * * [] MyCronJob my_cron_job2 0 1 * * * {"arg2":"foo"} MyCronJob2 -------------- ------------ ---------------- ------------
Install
$ php bin/console mw:cron:install New crontab content =================== * * * * * root /usr/local/Cellar/php/8.1.10_1/bin/php /source/bin/console mw:cron:run my_cron_job 0 1 * * * root /usr/local/Cellar/php/8.1.10_1/bin/php /source/bin/console mw:cron:run my_cron_job2 Confirm crontab? (yes/no) [yes]: > yes
Uninstall
$ php bin/console mw:cron:uninstall Uninstall cron jobs =================== [WARNING] The following cron jobs will be uninstalled: * * * * * root /usr/local/Cellar/php/8.1.10_1/bin/php /source/bin/console mw:cron:run my_cron_job 0 1 * * * root /usr/local/Cellar/php/8.1.10_1/bin/php /source/bin/console mw:cron:run my_cron_job2 Confirm uninstall? (yes/no) [yes]: >
mintware-de/native-cron-bundle 适用场景与选型建议
mintware-de/native-cron-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 226 次下载、GitHub Stars 达 6, 最近一次更新时间为 2022 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mintware-de/native-cron-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mintware-de/native-cron-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 226
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-03