FiveSecondTaskJob.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Jobs;
  3. use App\Services\BetService;
  4. use App\Services\PcIssueService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldBeUnique;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Queue\SerializesModels;
  11. use App\Services\IssueService;
  12. use Illuminate\Support\Facades\Log;
  13. class FiveSecondTaskJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. /**
  17. * 任务尝试次数
  18. */
  19. public $tries = 3;
  20. /**
  21. * 任务超时时间(秒)
  22. */
  23. public $timeout = 30;
  24. /**
  25. * Create a new job instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. //
  32. }
  33. /**
  34. * Execute the job.
  35. *
  36. * @return void
  37. */
  38. public function handle()
  39. {
  40. try {
  41. Log::error('🚀 开始执行15秒任务: ' . now());
  42. //自定义开奖
  43. PcIssueService::index();
  44. // 提前20秒提醒
  45. IssueService::syncCountdownIssue();
  46. // 同步停止
  47. IssueService::syncCloseIssue();
  48. // 获取最新的期号
  49. IssueService::getLatestIssue();
  50. //随机虚拟投注//随机最大人数:3人
  51. // BetService::randomVirtualBetting(3);
  52. // 重要:使用类名而不是 self(),避免递归
  53. FiveSecondTaskJob::dispatch()->delay(now()->addSeconds(15));
  54. Log::error('📅 下一个15秒任务已安排');
  55. } catch (\Exception $e) {
  56. Log::error('❌ 15秒任务执行异常: ' . $e->getMessage());
  57. // 异常后15秒重试
  58. FiveSecondTaskJob::dispatch()->delay(now()->addSeconds(15));
  59. }
  60. }
  61. // 可选:失败处理
  62. public function failed(\Throwable $exception)
  63. {
  64. Log::error('任务失败: ' . $exception->getMessage());
  65. // 可选:重新分发或通知
  66. dispatch(new self())->delay(now()->addSeconds(15));
  67. }
  68. }