OrderJob.php 827 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Jobs\Timer;
  3. use Hhxsv5\LaravelS\Swoole\Timer\CronJob;
  4. use Illuminate\Support\Facades\Log;
  5. use Swoole\Timer;
  6. class OrderJob extends CronJob
  7. {
  8. public function interval()
  9. {
  10. // 5分钟执行一次
  11. return 5 * 60 * 1000; // 定时器间隔,单位为 ms
  12. }
  13. /**
  14. * @return bool
  15. */
  16. public function isImmediate()
  17. {
  18. return $this->isImmediate;
  19. }
  20. public function setTimerId($timerId)
  21. {
  22. $this->timerId = $timerId;
  23. }
  24. public function stop()
  25. {
  26. if ($this->timerId && Timer::exists($this->timerId)) {
  27. Timer::clear($this->timerId);
  28. }
  29. }
  30. /**
  31. * 运行
  32. */
  33. public function run()
  34. {
  35. Log::info(__METHOD__, ['start', '', microtime(true)]);
  36. $this->stop();
  37. }
  38. }