dennis-sterkado/yii2-cron-manager
Composer 安装命令:
composer require dennis-sterkado/yii2-cron-manager
包简介
Simple and flexible background tasks manager module for Yii2 framework
README 文档
README
This is a simple and flexible module for creating\updating background tasks of cron application. It is designed to work with yii2 console controllers and description provides some advice to work with them.
Installation
Via composer
composer require --prefer-dist dennis-sterkado/yii2-cron-manager
or add to your composer.json
"dennis-sterkado/yii2-cron-manager": "*"
and
composer install
Add the code below to your web and console config files:
'modules' => [
'crontab' => [
'class' => 'sterkado\crontab\Module'
],
]
And finally
php yii migrate --migrationNamespaces=sterkado\\crontab\\migrations
To apply migrations via docker you might need to replace double backslashes with single.
Also make sure that cron is installed and running.
Configuration
Module requires a list of routes to yii2 console controllers. The list is used in gui to set up background tasks and form crontab lines. You can specify this by passing the controller classname with namespace into config file:
'source' => 'app\commands\HelloController'
or an array
'source' => [
'console\controllers\EmailController',
'console\controllers\UserController',
],
Module will parse controllers and form list of routes. Excluding actions from list if needed:
'exclude' => [
'/email/send'
],
or you can specify routes manually
'routes' => [
'/console/email/send',
'/console/user/proccess-order'
]
It is important to add "/" at the start to provide an absolute route. Don't forget to apply changes to both console and web configuration files.
Usage
Now you can manage background tasks in the module section of your application.
- Create Cron Task
- Add cron expression to schedule field
- Select a route from list
If your background task is using parameters you can add them as a json string in gui, then pass to controller action and decode.
public function actionTest($params)
{
$params = json_decode($params, true);
print $params['message'] . PHP_EOL;
return ExitCode::OK;
}
It is important to use PHP_EOL to write readable output to logs. Also module is using ExitCode class to normalize return values and it's recommended to design your actions accordingly to ExitCode constants. You can use them in exceptions as well:
if (empty($model)) {
throw new Exception('Unable to find model', ExitCode::DATAERR);
}
You don't need to try-catch exceptions since module is doing it by itself. This will form readable logs that are comfortable to support and search through.
Will be useful to check crontab file of php user to check if everything works correctly.
crontab -e -u www-data
Advanced configuration
Warning! Before you update settings that change crontab line (e.g phpBin, yiiBootstrapAlias, outputSetting), disable all of your active cron tasks.
Duplicating output to a file or STDOUT\STDERR:
'modules' => [
'crontab' => [
'class' => 'sterkado\crontab\Module'
...
'outputSetting' => '>> /var/log/app.log'
...
],
]
will form:
php yii /crontab/exec 1 >> /var/log/app.log
Setting path to php binary file manually:
'phpBin' => '/usr/bin/php'
Writing configs of crontab file:
'headLines' => [
'SHELL=/bin/sh',
'PATH=/usr/bin:/usr/sbin',
],
Setting crontab username This will work only in case PHP script is running from privileged user (e.g. 'root')
'crontabUsername' => 'www-data',
Setting path to yii bootstrap file
'yiiBootstrapAlias' => '@app/yii'
dennis-sterkado/yii2-cron-manager 适用场景与选型建议
dennis-sterkado/yii2-cron-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「manager」 「module」 「cron」 「background」 「Tasks」 「crontab」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dennis-sterkado/yii2-cron-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dennis-sterkado/yii2-cron-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dennis-sterkado/yii2-cron-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle to monitor and execute commands
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Scheduling extension for Yii2 framework
Monitoring for scheduled jobs
Temporal frequency library
Scheduling extension for Yii2 framework
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-07-29