More flexible way to manage your Laravel schedule tasks.
jiannei/laravel-schedule is a Laravel package for more flexible way to manage your laravel schedule tasks..
It currently has 19 GitHub stars and 1.875 downloads on Packagist (latest version v2.0.0).
Install it with composer require jiannei/laravel-schedule.
Discover more Laravel packages by jiannei
or browse all Laravel packages to compare alternatives.
Last updated
⏱ More flexible way to manage your Laravel schedule tasks. - 更灵活地管理 Laravel 应用中的任务调度。
Tips: 使用该扩展只是多了一种可以基于数据表维护任务调度的方式,不会破坏原先 Laravel 定义任务调度的方式,两种方式甚至可以组合使用。
$ composer require jiannei/laravel-schedule -vvv
$ php artisan vendor:publish --provider="Jiannei\Schedule\Laravel\Providers\LaravelServiceProvider"
php artisan migrate
为了能够更容易地集成到各种项目中,该扩展包并未直接提供一个 web 界面来维护 schedules 数据表,你可以按你的方式把 schedules 的配置维护进去就好。
举例说明项目中的使用方式:
INSERT INTO `schedules` (`id`, `description`, `command`, `parameters`, `expression`, `active`, `timezone`, `environments`, `without_overlapping`, `on_one_server`, `in_background`, `in_maintenance_mode`, `output_file_path`, `output_append`, `output_email`, `output_email_on_failure`, `created_at`, `updated_at`) VALUES (1, '爬取 Github daily 趋势', 'github:trending', NULL, '*/10 * * * *', 1, 'Asia/Shanghai', NULL, 0, 0, 1, 1, 'github_trending.log', 1, NULL, 0, NULL, NULL);
INSERT INTO `schedules` (`id`, `description`, `command`, `parameters`, `expression`, `active`, `timezone`, `environments`, `without_overlapping`, `on_one_server`, `in_background`, `in_maintenance_mode`, `output_file_path`, `output_append`, `output_email`, `output_email_on_failure`, `created_at`, `updated_at`) VALUES (2, '爬取 Github weekly 趋势', 'github:trending', '--since=weekly', '59 23 * * *', 1, 'Asia/Shanghai', NULL, 0, 0, 1, 1, 'github_trending.log', 1, NULL, 0, NULL, NULL);
INSERT INTO `schedules` (`id`, `description`, `command`, `parameters`, `expression`, `active`, `timezone`, `environments`, `without_overlapping`, `on_one_server`, `in_background`, `in_maintenance_mode`, `output_file_path`, `output_append`, `output_email`, `output_email_on_failure`, `created_at`, `updated_at`) VALUES (3, '爬取 Github monthly 趋势', 'github:trending', '--since=monthly', '59 23 * * *', 1, 'Asia/Shanghai', NULL, 0, 0, 1, 1, 'github_trending.log', 1, NULL, 0, NULL, NULL);
说明:
- command,应用程序中已经定义并且需要自动调度的 command
- parameters,对应 command 执行时指定的参数
- expression,执行时间间隔,cron 表达式
- active,0 开启,1 关闭
- output_file_path,指定 command 的输出的文件路径
- output_append,command 输出到文件时是否进行追加
- output_email,command 输出发送邮件
- output_email_on_failure,只在 command 执行失败时发送输出到邮件
- 其他参数均可以在 laravel schedule 文档中找到相应的函数说明:https://laravel.com/docs/8.x/scheduling#introduction
php artisan schedule:list检验是否配置成功+------------------------------------------------------------------------+--------------+--------------------------+----------------------------+
| Command | Interval | Description | Next Due |
+------------------------------------------------------------------------+--------------+--------------------------+----------------------------+
| '/www/server/php/80/bin/php' 'artisan' github:trending | */10 * * * * | 爬取 Github daily 趋势 | 2021-06-22 21:40:00 +08:00 |
| '/www/server/php/80/bin/php' 'artisan' github:trending --since=weekly | 59 23 * * * | 爬取 Github weekly 趋势 | 2021-06-22 23:59:00 +08:00 |
| '/www/server/php/80/bin/php' 'artisan' github:trending --since=monthly | 59 23 * * * | 爬取 Github monthly 趋势 | 2021-06-22 23:59:00 +08:00 |
+------------------------------------------------------------------------+--------------+--------------------------+----------------------------+
php artisan schedule:run以上,基于 schedules 数据表来管理调度任务就完成了。
MIT 许可证(MIT)。有关更多信息,请参见协议文件。