| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?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('inspire')->hourly();
- // 每天12:00执行
- $schedule->command('task:daily')->dailyAt('12:00')
- ->timezone('Asia/Shanghai') // 设置时区,可选
- ->runInBackground() // 在后台运行,可选
- ->withoutOverlapping() // 防止任务重叠执行
- ->appendOutputTo(storage_path('logs/daily-task.log')) // 输出到日志文件
- ->onOneServer(); // 如果使用多服务器,确保只在一台服务器上运行
- }
- /**
- * Register the commands for the application.
- *
- * @return void
- */
- protected function commands()
- {
- $this->load(__DIR__ . '/Commands');
- require base_path('routes/console.php');
- }
- }
|