| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Console;
- use Illuminate\Console\Scheduling\Schedule;
- use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
- class Kernel extends ConsoleKernel
- {
- /**
- * 定义应用的自定义 Artisan 命令
- *
- * @var array
- */
- protected $commands = [
- Commands\DailyTask::class,
- ];
- /**
- * Define the application's command schedule.
- *
- * @param \Illuminate\Console\Scheduling\Schedule $schedule
- * @return void
- */
- protected function schedule(Schedule $schedule)
- {
- $schedule->command('task:daily')
- ->timezone('Asia/Shanghai') // 设置时区,可选
- ->runInBackground() // 在后台运行,可选
- ->withoutOverlapping() // 防止任务重叠执行
- ->appendOutputTo(storage_path('logs/daily-task.log')) // 输出到日志文件
- ->onOneServer(); // 如果使用多服务器,确保只在一台服务器上运行
- // 每天17:00执行
- $schedule->command('task:city_warning_notice')
- ->dailyAt('17:00')
- ->timezone('Asia/Shanghai') // 设置时区,可选
- ->runInBackground() // 在后台运行,可选
- ->appendOutputTo(storage_path('logs/city-warning-notice-task.log')) // 输出到日志文件
- ->onOneServer(); // 如果使用多服务器,确保只在一台服务器上运行
- }
- /**
- * Register the commands for the application.
- *
- * @return void
- */
- protected function commands()
- {
- $this->load(__DIR__ . '/Commands');
- require base_path('routes/console.php');
- }
- }
|