seven vor 1 Tag
Ursprung
Commit
4caefde8cd
1 geänderte Dateien mit 29 neuen und 5 gelöschten Zeilen
  1. 29 5
      app/Jobs/FiveSecondTaskJob.php

+ 29 - 5
app/Jobs/FiveSecondTaskJob.php

@@ -15,6 +15,17 @@ class FiveSecondTaskJob implements ShouldQueue
 {
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
+     /**
+     * 任务尝试次数
+     */
+    public $tries = 3;
+
+    /**
+     * 任务超时时间(秒)
+     */
+    public $timeout = 30;
+
+
     /**
      * Create a new job instance.
      *
@@ -32,11 +43,24 @@ class FiveSecondTaskJob implements ShouldQueue
      */
     public function handle()
     {
-         // 你的业务逻辑
-        IssueService::getLatestIssue(); // 获取最新的期号
-        
-        // 重要:5秒后再次分发自己
-        dispatch(new self())->delay(now()->addSeconds(5));
+        try {
+            Log::info('🚀 开始执行5秒任务: ' . now());
+            
+            // 你的业务逻辑
+            $latestIssue = IssueService::getLatestIssue(); // 获取最新的期号
+            // Log::info('✅ 获取到最新期号: ' . ($latestIssue ?? '无'));
+            
+            // 重要:使用类名而不是 self(),避免递归
+            FiveSecondTaskJob::dispatch()->delay(now()->addSeconds(5));
+            
+            Log::info('📅 下一个5秒任务已安排');
+            
+        } catch (\Exception $e) {
+            Log::error('❌ 5秒任务执行异常: ' . $e->getMessage());
+            
+            // 异常后10秒重试
+            FiveSecondTaskJob::dispatch()->delay(now()->addSeconds(10));
+        }
     }
 
      // 可选:失败处理