sparkinzy / laravel-schedule-command
在命令中直接定义定时任务,避免在Kernel中定义大量定时任务
1.0.2
2021-07-16 08:01 UTC
Requires
- illuminate/console: ^6.2
- illuminate/support: ^6.2
- symfony/finder: ^5.2
README
在命令中直接定义定时任务,避免在Kernel中定义大量定时任务。
安装
$ composer require sparkinzy/laravel-schedule-command -vvv
使用方法
以下为参考示例
# 文件 app/Console/Commands/TestCommand.php <?php namespace App\Console\Commands; use Illuminate\Console\Scheduling\Schedule; use Sparkinzy\LaravelScheduleCommand\Commands\ScheduleCommand; class AdvertAutoDelete extends ScheduleCommand { /** * The name and signature of the console command. * * @var string */ protected $signature = 'test:schedule'; /** * The console command description. * * @var string */ protected $description = '测试命令自带定时任务配置'; /** * Execute the console command. * * @return mixed */ public function handle() { } /** * @param Schedule $schedule * 此命令每分钟执行一次 */ public function schedule(Schedule $schedule) { #$schedule->command(static::class) # ->everyMinute() # ->runInBackground(); # 定时任务执行时带参数 $schedule->command(static::class,['param1'=>'1']) ->everyMinute() ->runInBackground(); } }
安装后,修改命令重新继承 sparkinzy\LaravelScheduleCommand\Commands\ScheduleCommand
并在命令中新增function schedule(Schedule $schedule){
}
贡献
您可以通过以下三种方式之一进行贡献
代码贡献过程并不非常正式。您只需确保遵循PSR-0、PSR-1和PSR-2编码指南。任何新的代码贡献都必须附有适用的单元测试。
许可
MIT