64 lines
2.4 KiB
PHP
64 lines
2.4 KiB
PHP
<?php
|
|
namespace app\api\job;
|
|
use think\queue\Job;
|
|
use app\common\QueueJob;
|
|
use app\common\Reviewer;
|
|
class RevisionReviewer
|
|
{
|
|
// 文章退修任务
|
|
public function fire(Job $job, $data)
|
|
{
|
|
|
|
// 记录任务开始执行
|
|
$sLogPath = ROOT_PATH.'public/queue_log/RevisionReviewer_'.date('Ymd').'.log';
|
|
file_put_contents($sLogPath,'-----------Queue job started-----------' . json_encode($data)."\n",FILE_APPEND);
|
|
|
|
//获取任务ID
|
|
$iLogId = 0;
|
|
try {
|
|
//实例化
|
|
$oQueueJob = new QueueJob;
|
|
$sMsg = '处理审稿人同意审稿但超时未审的数据成功';
|
|
|
|
$aJob = empty($job->getRawBody()) ? [] : json_decode($job->getRawBody(), true);
|
|
$aParam = [
|
|
'job_id' => empty($aJob['id']) ? 'RevisionReviewer'.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'];
|
|
if (!empty($iArticleId)) {
|
|
$aParam = ['article_id' => $iArticleId];
|
|
$oReviewer = new Reviewer;
|
|
$aResult = json_decode($oReviewer->revisionForReviewer($aParam),true);
|
|
$sMsg = empty($aResult['msg']) ? '审稿人同意审稿但超时未审的数据失败' : $aResult['msg'];
|
|
}
|
|
|
|
$job->delete();
|
|
|
|
//更新任务状态
|
|
$aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg];
|
|
$oQueueJob->updateLog($aParam);
|
|
//记录日志
|
|
file_put_contents($sLogPath,'-----------Queue job end---------'."\n\n\n",FILE_APPEND);
|
|
} 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();
|
|
|
|
}finally {
|
|
gc_collect_cycles(); // 强制垃圾回收
|
|
}
|
|
}
|
|
|
|
} |