oQueueJob = new QueueJob; $this->QueueRedis = QueueRedis::getInstance(); } public function fire(Job $job, $data) { $this->oQueueJob->init($job); $rawBody = empty($job->getRawBody()) ? '' : $job->getRawBody(); $jobData = empty($rawBody) ? [] : json_decode($rawBody, true); $jobId = empty($jobData['id']) ? 'unknown' : $jobData['id']; $this->oQueueJob->log("-----------队列任务开始-----------"); $this->oQueueJob->log("当前任务ID: {$jobId}, 尝试次数: {$job->attempts()}"); $iPArticleId = empty($data['p_article_id']) ? 0 : intval($data['p_article_id']); $iPReferId = empty($data['p_refer_id']) ? 0 : intval($data['p_refer_id']); if (empty($iPArticleId) || empty($iPReferId)) { $this->oQueueJob->log("无效的 p_article_id 或 p_refer_id,删除任务"); $job->delete(); return; } try { $sClassName = get_class($this); $sRedisKey = "queue_job:{$sClassName}:{$iPArticleId}:{$iPReferId}"; $sRedisValue = uniqid() . '_' . getmypid(); if (!$this->oQueueJob->acquireLock($sRedisKey, $sRedisValue, $job)) { return; } (new ReferenceDispatchService())->dispatchReferByType($iPReferId); $this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie, $sRedisValue); $job->delete(); $this->oQueueJob->log("任务执行成功 | 日志ID: {$sRedisKey} | p_refer_id:{$iPReferId}"); } catch (\RuntimeException $e) { $this->oQueueJob->handleRetryableException($e, $sRedisKey, $sRedisValue, $job); } catch (\LogicException $e) { $this->oQueueJob->handleNonRetryableException($e, $sRedisKey, $sRedisValue, $job); } catch (\Exception $e) { $this->oQueueJob->handleRetryableException($e, $sRedisKey, $sRedisValue, $job); } finally { $this->oQueueJob->finnal(); } } }