|
|
@@ -0,0 +1,68 @@
|
|
|
+<?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 Illuminate\Support\Facades\Log;
|
|
|
+
|
|
|
+class PaymentJob implements ShouldQueue
|
|
|
+{
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 任务尝试次数
|
|
|
+ */
|
|
|
+ public $tries = 3;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 任务超时时间(秒)
|
|
|
+ */
|
|
|
+ public $timeout = 30;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create a new job instance.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Execute the job.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function handle()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ Log::error('🚀 开始执行更新订单状态任务: ' . now());
|
|
|
+
|
|
|
+
|
|
|
+ Log::error('📅 下一个更新订单状态任务已安排');
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('❌ 更新订单状态任务执行异常: ' . $e->getMessage());
|
|
|
+
|
|
|
+ // 异常后15秒重试
|
|
|
+ PaymentJob::dispatch()->delay(now()->addSeconds(15));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 可选:失败处理
|
|
|
+ public function failed(\Throwable $exception)
|
|
|
+ {
|
|
|
+ Log::error('更新订单状态任务失败: ' . $exception->getMessage());
|
|
|
+
|
|
|
+ // 可选:重新分发或通知
|
|
|
+ dispatch(new self())->delay(now()->addSeconds(15));
|
|
|
+ }
|
|
|
+}
|