StartFiveSecondTask.php 822 B

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