trogers1884/laravel-schedule-mgt
Composer 安装命令:
composer require trogers1884/laravel-schedule-mgt
包简介
A Laravel package for managing scheduled tasks through file storage
README 文档
README
A Laravel package for managing scheduled tasks through file storage, allowing dynamic configuration of Laravel's task scheduler without code changes.
Features
- Manage scheduled tasks without modifying code
- Store task configurations in JSON files
- Toggle tasks on/off without deployment
- Add custom parameters and constraints to scheduled tasks
- Command-line interface for task management
- No database dependencies required
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
Installation
You can install the package via composer:
composer require trogers1884/laravel-schedule-mgt
The package will automatically register its service provider.
Configuration
Publish the configuration file:
php artisan vendor:publish --tag="schedule-mgt-config"
This will create a config/schedule-mgt.php file with the following contents:
return [ 'storage_path' => storage_path('app/schedule-mgt'), 'file_format' => 'json', ];
Laravel Version-Specific Setup
Laravel 11
Add to your routes/console.php:
use Trogers1884\LaravelScheduleMgt\ScheduleManager; ScheduleManager::schedule();
Laravel 10
Add to your app/Console/Kernel.php in the schedule method:
use Trogers1884\LaravelScheduleMgt\ScheduleManager; protected function schedule(Schedule $schedule) { ScheduleManager::schedule(); }
Important Notes
- For Laravel 10 and above, ensure your
config/app.phphas the package service provider if it's not auto-discovered:'providers' => [ // ... Trogers1884\LaravelScheduleMgt\ScheduleMgtServiceProvider::class, ],
Usage
Managing Tasks via Console Commands
List All Tasks
php artisan schedule:list
Add a New Task
phpphp artisan schedule:add "command:name" \ # Note: The first argument is now 'task' internally --frequency=daily \ --parameters='["--param1", "value1"]' \ --freq-parameters='["21:00"]' \ --constraints='[{"method":"environments", "parameters":["production"]}]'
Options:
- First argument: The artisan command to schedule
--frequency: The scheduling frequency (daily, hourly, weekly, etc.)--parameters: JSON array of command parameters--freq-parameters: JSON array of frequency method parameters--constraints: JSON array of additional scheduling constraints--inactive: Set the task as inactive initially
Toggle Task Status
php artisan schedule:toggle 1 --active=0
Remove a Task
php artisan schedule:remove 1
This will completely remove the task with ID 1. You'll be asked to confirm before the task is removed. This action cannot be undone.
Frequency Methods
You can use any of Laravel's schedule frequency methods:
hourly()daily()weekly()monthly()quarterly()yearly()timezone()at()dailyAt()twiceDaily()weeklyOn()monthly()monthlyOn()lastDayOfMonth()quarterly()yearly()cron()everyMinute()everyTwoMinutes()everyThreeMinutes()everyFourMinutes()everyFiveMinutes()everyTenMinutes()everyFifteenMinutes()everyThirtyMinutes()
Available Constraints
You can add any of Laravel's schedule constraints:
environments(['production'])evenInMaintenanceMode()withoutOverlapping()onOneServer()between('8:00', '17:00')unlessBetween('23:00', '4:00')when(closure)skip(closure)runInBackground()
Example Tasks
Basic Daily Task
php artisan schedule:add "cache:clear" --frequency=daily
Weekly Backup with Parameters
php artisan schedule:add "backup:run" \ --frequency=weekly \ --freq-parameters='["monday", "3:00"]' \ --parameters='["--only-db"]' \ --constraints='[{"method":"environments", "parameters":["production"]}]'
Hourly Task with Multiple Constraints
php artisan schedule:add "queue:work" \ --frequency=hourly \ --constraints='[ {"method":"withoutOverlapping"}, {"method":"environments", "parameters":["production"]}, {"method":"evenInMaintenanceMode"}, {"method":"runInBackground"} ]'
Testing the Package
Run the test suite:
composer test
Uninstallation
To completely remove the package from your Laravel project:
- Remove your schedule configuration from your Laravel project:
- For Laravel 11: Remove the
ScheduleManager::schedule();line fromroutes/console.php - For Laravel 10: Remove the
ScheduleManager::schedule();line fromapp/Console/Kernel.php
- Remove the published configuration file:
rm config/schedule-mgt.php
- Remove the stored task data (optional):
rm -rf storage/app/schedule-mgt
- Uninstall the package via composer:
composer remove trogers1884/laravel-schedule-mgt
Security
If you discover any security related issues, please use the issue tracker located at https://github.com/trogers1884/laravel-schedule-mgt/issues .
Credits
License
The MIT License (MIT). Please see License File for more information.
trogers1884/laravel-schedule-mgt 适用场景与选型建议
trogers1884/laravel-schedule-mgt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 trogers1884/laravel-schedule-mgt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 trogers1884/laravel-schedule-mgt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-06