StartFiveSecondTask.php 906 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Jobs\FiveSecondTaskJob;
  5. use Illuminate\Support\Facades\Log;
  6. class StartFiveSecondTask extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'five_task';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. /**
  21. * Execute the console command.
  22. *
  23. * @return int
  24. */
  25. public function handle()
  26. {
  27. $this->info('启动10秒循环任务...');
  28. Log::error('启动10秒循环任务...'.now());
  29. // 首次启动任务
  30. FiveSecondTaskJob::dispatch()->delay(now()->addSeconds(10));
  31. $this->info('任务已启动,将在10秒后首次执行');
  32. return Command::SUCCESS;
  33. }
  34. }