processAutoCreateAllotRules($data, $job->attempts())) { $job->delete(); Log::info('自动创建分配规则任务执行成功,时间:' . date('Y-m-d H:i:s')); } else { if ($job->attempts() > 3) { // 超过重试次数,删除任务 Log::error('自动创建分配规则任务执行失败,已超过重试次数'); $job->delete(); } else { // 任务失败,重新放回队列 Log::warning('自动创建分配规则任务执行失败,重试次数:' . $job->attempts()); $job->release(Config::get('queue.failed_delay', 10)); } } } catch (\Exception $e) { // 出现异常,记录日志 Log::error('自动创建分配规则任务异常:' . $e->getMessage()); if ($job->attempts() > 3) { $job->delete(); } else { $job->release(Config::get('queue.failed_delay', 10)); } } } /** * 处理自动创建分配规则 * @param array $data 任务数据 * @param int $attempts 重试次数 * @return bool */ protected function processAutoCreateAllotRules($data, $attempts) { Log::info('开始执行自动创建分配规则任务,重试次数:' . $attempts); // 实例化控制器 $allotRuleController = new AllotRuleController(); // 调用自动创建分配规则方法 $result = $allotRuleController->autoCreateAllotRules([], true); $response = json_decode($result, true); // 判断是否成功 if (isset($response['code']) && $response['code'] == 200) { Log::info('自动创建分配规则成功:' . json_encode($response['data'])); return true; } else { $errorMsg = isset($response['msg']) ? $response['msg'] : '未知错误'; Log::error('自动创建分配规则失败:' . $errorMsg); return false; } } }