队列
This commit is contained in:
40
application/api/job/WechatMaterial.php
Normal file
40
application/api/job/WechatMaterial.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
use think\Log;
|
||||
use think\queue\Job;
|
||||
use app\api\controller\Aiarticle;
|
||||
class WechatMaterial
|
||||
{
|
||||
// 上传素材任务入口
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
|
||||
try {
|
||||
// 步骤1:上传素材(图片)
|
||||
if (!empty($data['article_id'])) {
|
||||
$oAiarticle = new Aiarticle;
|
||||
// $aResult = json_decode($oAiarticle->uploadMaterial($data),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? '' : $aResult['msg'];
|
||||
if ($iStatus != 1) {
|
||||
$iStatus = 2;
|
||||
$sMsg = empty($sMsg) ? '素材上传失败' : $sMsg;
|
||||
}
|
||||
//插入日志记录
|
||||
$aLogInfo = ['article_id' => $data['article_id'],'type' => 1,'msg' =>$sMsg,'status' => $iStatus,'create_time' => time()];
|
||||
$result = json_decode($oAiarticle->addWechatLog($aLogInfo),true);
|
||||
$iStatus = empty($result['status']) ? 0 : $result['status'];
|
||||
$sMsg = empty($result['msg']) ? '插入日志记录失败' : $result['msg'];
|
||||
if($iStatus != 1){
|
||||
Log::error($sMsg."\n".json_encode($aLogInfo) . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("上传素材任务异常:" . $e->getMessage());
|
||||
}finally {
|
||||
gc_collect_cycles(); // 强制垃圾回收
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user