队列任务加日志
This commit is contained in:
@@ -8,6 +8,9 @@ class ReviewerScore
|
||||
// 审稿人评分
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
// 记录任务开始执行
|
||||
$sLogPath = ROOT_PATH.'public/queue_log/ReviewerScore_'.date('Ymd').'.log';
|
||||
file_put_contents($sLogPath,'-----------Queue job started-----------' . json_encode($data)."\n",FILE_APPEND);
|
||||
|
||||
//获取任务ID
|
||||
$iLogId = 0;
|
||||
@@ -15,35 +18,35 @@ class ReviewerScore
|
||||
//实例化
|
||||
$oQueueJob = new QueueJob;
|
||||
$sMsg = '给审稿人评分处理成功';
|
||||
if(!empty($job->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);
|
||||
|
||||
$aJob = empty($job->getRawBody()) ? [] : json_decode($job->getRawBody(), true);
|
||||
$aParam = [
|
||||
'job_id' => empty($aJob['id']) ? 'ReviewerScore'.rand(100, 999) : $aJob['id'],
|
||||
'job_class' => get_class($this),
|
||||
'status' => 0,
|
||||
'create_time' => time(),
|
||||
'params' => json_encode($data, JSON_UNESCAPED_UNICODE)
|
||||
];
|
||||
$iLogId = $oQueueJob->addLog($aParam);
|
||||
|
||||
//审稿人评分
|
||||
$iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];//文章ID
|
||||
$iReviewerId = empty($data['reviewer_id']) ? 0 : $data['reviewer_id'];//审稿人ID
|
||||
$iArtRevId = empty($data['art_rev_id']) ? 0 : $data['art_rev_id'];//主键ID
|
||||
if (!empty($iArticleId) && !empty($iArtRevId) && !empty($iArtRevId)) {
|
||||
$aParam = ['article_id' => $iArticleId,'reviewer_id' => $iReviewerId,'art_rev_id' => $iArtRevId];
|
||||
$oReviewer = new Reviewer;
|
||||
$aResult = json_decode($oReviewer->score($aParam),true);
|
||||
$sMsg = empty($aResult['msg']) ? '给审稿人评分处理失败' : $aResult['msg'];
|
||||
}
|
||||
//审稿人评分
|
||||
$iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];//文章ID
|
||||
$iReviewerId = empty($data['reviewer_id']) ? 0 : $data['reviewer_id'];//审稿人ID
|
||||
$iArtRevId = empty($data['art_rev_id']) ? 0 : $data['art_rev_id'];//主键ID
|
||||
if (!empty($iArticleId) && !empty($iArtRevId) && !empty($iArtRevId)) {
|
||||
$aParam = ['article_id' => $iArticleId,'reviewer_id' => $iReviewerId,'art_rev_id' => $iArtRevId];
|
||||
$oReviewer = new Reviewer;
|
||||
$aResult = json_decode($oReviewer->score($aParam),true);
|
||||
$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("RecommendReviewer延迟任务执行成功: ".json_encode($data));
|
||||
// 记录日志
|
||||
file_put_contents($sLogPath,'-----------Queue job end---------'."\n\n\n",FILE_APPEND);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
//实例化
|
||||
@@ -53,8 +56,7 @@ class ReviewerScore
|
||||
$aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg];
|
||||
$oQueueJob->updateLog($aParam);
|
||||
$job->delete();
|
||||
// // 记录错误日志
|
||||
// \think\Log::error("RecommendReviewer延迟任务失败: ".$e->getMessage());
|
||||
|
||||
}finally {
|
||||
gc_collect_cycles(); // 强制垃圾回收
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user