seven hace 3 días
padre
commit
dfb5db1645
Se han modificado 1 ficheros con 50 adiciones y 0 borrados
  1. 50 0
      app/Jobs/FiveSecondTaskJob.php

+ 50 - 0
app/Jobs/FiveSecondTaskJob.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+use App\Services\IssueService;
+use Illuminate\Support\Facades\Log;
+
+class FiveSecondTaskJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+         // 你的业务逻辑
+        IssueService::getLatestIssue(); // 获取最新的期号
+        
+        // 重要:5秒后再次分发自己
+        dispatch(new self())->delay(now()->addSeconds(5));
+    }
+
+     // 可选:失败处理
+    public function failed(\Throwable $exception)
+    {
+        Log::error('任务失败: ' . $exception->getMessage());
+        
+        // 可选:重新分发或通知
+        dispatch(new self())->delay(now()->addSeconds(5));
+    }
+}