FiveSecondTaskJob.php 2.2 KB

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