elstc/cakephp-cron-jobs
Composer 安装命令:
composer require elstc/cakephp-cron-jobs
包简介
A cron job runner for CakePHP
README 文档
README
This plugin is a simple wrapper for crunzphp/crunz.
Version Map
| CakePHP Version | Plugin Version | Branch |
|---|---|---|
| 5.x | 3.x | cake5 |
| 4.x | 2.x | cake4 |
| 3.x | 0.3.x | cake3 |
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require elstc/cakephp-cron-jobs
Load plugin
Load the plugin by adding the following statement in your project's src/Application.php:
$this->addPlugin('Elastic/CronJobs');
Generate config file
Run bin/cake CronJobs publish:config command.
The command generates crunz.yml in the project ROOT directory.
You can configure it with crunz.yml, see also https://github.com/crunzphp/crunz#configuration
I recommend changing source: to:
source: vendor/elstc/cakephp-cron-jobs/tasks
This makes it unnecessary to specify a directory when using schedule:run and schedule:list command.
Register to cron
Add your cron schedule using crontab -e:
* * * * * cd {YOUR-APP-DIR}; bin/cake CronJobs schedule:run vendor/elstc/cakephp-cron-jobs/tasks/
Usage
You can register a scheduled job from the CakePHP event system.
Register to job scheduler in bootstrap_cli.php using the CakePHP event system:
use Cake\Event\Event; use Cake\Event\EventManager; EventManager::instance()->on('CronJobs.buildSchedule', static function (Event $event) { /** @type \Elastic\CronJobs\Schedule\CakeSchedule $schedule */ $schedule = $event->getSubject(); // Add a scheduled command $schedule->run('touch tmp/crunz-time-from-event') ->description('your job description') ->everyDay() ->at('09:00'); // Add a scheduled cake's command // such as `bin/cake your_command command_arg1 --command-option --some-opt=value` $schedule->runCommand('your_command', [ 'command_arg1', '--command-option', '--some-opt' => 'value', ]) ->description('your job description') ->cron('0 3 * * *'); });
\Elastic\CronJobs\Schedule\CakeSchedule is a \Crunz\Schedule wrapper class.
See also: crunzphp/crunz README
Show scheduled jobs
bin/cake CronJobs schedule:list vendor/elstc/cakephp-cron-jobs/tasks/
Upgrade from CakePHP 3
crunzphp/crunz updated from 1.12 to 2.x (<= PHP 7.3), 3.x (>= PHP 7.4). See also crunz's Upgrade Guide.
elstc/cakephp-cron-jobs 适用场景与选型建议
elstc/cakephp-cron-jobs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.13k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 11 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 elstc/cakephp-cron-jobs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elstc/cakephp-cron-jobs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-09