diontech/laravel-extended-scheduler
Composer 安装命令:
composer require diontech/laravel-extended-scheduler
包简介
This package allows you to configure the scheduled tasks of the app via (database) model. It was developed to avoid handling theseconfigurations via a config file only, cause then we cannot share the same repo to n server instances when running different tasks is needed at each server.
README 文档
README
Extend Laravel scheduler to can config tasks via model
This package allows you to configure the scheduled tasks of the app via (database) model. It was developed to avoid handling these configurations via a config file only, cause then we cannot share the same repo to n server instances when running different tasks is needed at each server.
This package will extend the laravel scheduler, so all coded scheduled tasks will still be available.
releases / laravel support
- laravel 8: v1.2.x
- laravel 9: v1.3.x
installation
composer require diontech/laravel-extended-scheduler
php artisan migrate
using
Facade based handling
Instead of used model based handling mentioned below, you can also do Facade based handling, like:
\DionTech\Scheduler\Support\Facades\ScheduledCommand\ScheduledCommand::arguments([ 'foo' ])->fluent([ 'cron' => [ '* * * * *' ] ])->isActive() ->create();
Model based handling
At the moment you can do something similar to the following:
\DionTech\Scheduler\Models\ScheduledCommand::create([ 'method' => 'command', 'arguments' => [ 'schedule:list' ], 'fluent' => [ 'cron' => ['* * * * *'] ], 'is_active' => true ]); \DionTech\Scheduler\Models\ScheduledCommand::create([ 'method' => 'command', 'arguments' => [ 'foo' ], 'fluent' => [ 'weekdays', 'hourly', 'timezone' => ['America/Chicago'], 'between' => ['8:00', '17:00'] ], 'is_active' => true ]); \DionTech\Scheduler\Models\ScheduledCommand::create([ 'method' => 'command', 'arguments' => [ 'test:command', ['Taylor', '--force'] ], 'fluent' => [ 'daily' ], 'is_active' => true ]); \DionTech\Scheduler\Models\ScheduledCommand::create([ 'method' => 'job', 'arguments' => [ 'new \App\Jobs\TestJob', 'sqs' ], 'fluent' => [ 'everyFiveMinutes' ], 'is_active' => true ]);
See https://laravel.com/docs/8.x/scheduling to get an idea of how it can be used.
normalizing inserted model to readable structure
$model = \DionTech\Scheduler\Models\ScheduledCommand::create([ 'method' => 'command', 'arguments' => [ 'foo' ], 'fluent' => [ 'weekdays', 'hourly', 'timezone' => ['America/Chicago'], 'between' => ['8:00', '17:00'] ], 'is_active' => true ]); $event = $model->event(); //returns \Illuminate\Console\Scheduling\Event $command = $event->command; //something like "/usr/local/Cellar/php@7.4/7.4.16/bin/php' 'artisan' foo" $expression = $event->expression; //something like "0 * * * 1-5" $description = $event->description; //something like "new \App\Jobs\TestJob"
make a command active / inactive
Each ScheduledCommand can be set to inactive / active by its property 'is_active'. the default value is false, so you must explicitly activate the command to be recognized in the laravel scheduler.
add description / notices to the command
Each ScheduledCommand have a property 'description', where you can save additional notices if needed.
get all registered / available commands of your application
model based
$commands = (new \DionTech\Scheduler\Support\Helper\CommandLister)->all();
request response based
insert this in your controller, that's it:
return (new \DionTech\Scheduler\Http\Responses\ListAllCommandsResponse()) ->toResponse($request);
NextSteps
- writing an API class
- make getCommands() method cacheable
- build some configs
diontech/laravel-extended-scheduler 适用场景与选型建议
diontech/laravel-extended-scheduler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.79k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 diontech/laravel-extended-scheduler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 diontech/laravel-extended-scheduler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-26