diff --git a/application/api/job/ArticleAiCreateContent.php b/application/api/job/ArticleAiCreateContent.php new file mode 100644 index 0000000..23b2a01 --- /dev/null +++ b/application/api/job/ArticleAiCreateContent.php @@ -0,0 +1,61 @@ +getRawBody())){ + $aJob = json_decode($job->getRawBody(), true); + $aParam = [ + 'job_id' => empty($aJob['id']) ? '' : $aJob['id'], + 'job_class' => get_class($this), + 'status' => 0, + 'create_time' => time(), + 'params' => json_encode($aJob, JSON_UNESCAPED_UNICODE) + ]; + $iLogId = $oQueueJob->addLog($aParam); + // 步骤1:上传素材(图片) + $iArticleId = empty($data['article_id']) ? 0 : $data['article_id']; + if (!empty($iArticleId)) { + //上传素材 + $oAiarticle = new Aiarticle; + $aResult = json_decode($oAiarticle->create($data),true); + $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; + $sMsg = empty($aResult['msg']) ? '文章AI内容声场失败' : $aResult['msg']; + } + } + $job->delete(); + + //更新任务状态 + $aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + // // 记录日志 + // \think\Log::info("ArticleAiCreateContent延迟任务执行成功: ".json_encode($data)); + } catch (\Exception $e) { + + //实例化 + $oQueueJob = new QueueJob; + //更新任务状态 + $sMsg = empty($e->getMessage()) ? '任务出错' : $e->getMessage(); + $aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + $job->delete(); + // // 记录错误日志 + // \think\Log::error("ArticleAiCreateContent延迟任务失败: ".$e->getMessage()); + }finally { + gc_collect_cycles(); // 强制垃圾回收 + } + } + +} \ No newline at end of file diff --git a/application/api/job/WechatDraftPublish.php b/application/api/job/WechatDraftPublish.php new file mode 100644 index 0000000..54d9924 --- /dev/null +++ b/application/api/job/WechatDraftPublish.php @@ -0,0 +1,62 @@ +getRawBody())){ + $aJob = json_decode($job->getRawBody(), true); + $aParam = [ + 'job_id' => empty($aJob['id']) ? '' : $aJob['id'], + 'job_class' => get_class($this), + 'status' => 0, + 'create_time' => time(), + 'params' => json_encode($aJob, JSON_UNESCAPED_UNICODE) + ]; + $iLogId = $oQueueJob->addLog($aParam); + // 步骤1:上传素材(图片) + $iArticleId = empty($data['article_id']) ? 0 : $data['article_id']; + if (!empty($iArticleId)) { + //上传素材 + $oAiarticle = new Aiarticle; + $aResult = json_decode($oAiarticle->publishDraft($data),true); + $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; + $sMsg = empty($aResult['msg']) ? '草稿箱发布失败' : $aResult['msg']; + } + } + $job->delete(); + + //更新任务状态 + $aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + // // 记录日志 + // \think\Log::info("WechatDraft-延迟任务执行成功: ".json_encode($data)); + } catch (\Exception $e) { + + //实例化 + $oQueueJob = new QueueJob; + //更新任务状态 + $sMsg = empty($e->getMessage()) ? '任务出错' : $e->getMessage(); + $aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + $job->delete(); + // // 记录错误日志 + // \think\Log::error("WechatDraft-延迟任务失败: ".$e->getMessage()); + }finally { + gc_collect_cycles(); // 强制垃圾回收 + } + } + +} \ No newline at end of file