参看文献再次更新
This commit is contained in:
@@ -1932,7 +1932,8 @@ class Production extends Base
|
||||
}
|
||||
|
||||
$this->referToDoi($data['p_article_id']);
|
||||
(new ReferenceDispatchService())->dispatchRefersByType($data['p_article_id']);
|
||||
// 每条文献单独入队,接口立即返回;多 worker 可并行处理 200+ 条
|
||||
(new ReferenceDispatchService())->enqueueRefersByType($data['p_article_id']);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
@@ -1999,7 +2000,7 @@ class Production extends Base
|
||||
|
||||
public function doiTofrag($p_article_id)
|
||||
{
|
||||
(new ReferenceDispatchService())->dispatchRefersByType($p_article_id);
|
||||
(new ReferenceDispatchService())->enqueueRefersByType($p_article_id);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
70
application/api/job/ReferenceDispatchQueue.php
Normal file
70
application/api/job/ReferenceDispatchQueue.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\QueueRedis;
|
||||
use app\common\ReferenceDispatchService;
|
||||
|
||||
/**
|
||||
* 单条参考文献分流(journal/book/other)异步任务。
|
||||
* freshRefers 按 p_refer_id 逐条入队,多条文献由多个 worker 并行处理。
|
||||
*
|
||||
* Worker:
|
||||
* php think queue:work --queue ReferenceDispatchQueue,ArticleReferDetailQueue
|
||||
*/
|
||||
class ReferenceDispatchQueue
|
||||
{
|
||||
private $oQueueJob;
|
||||
private $QueueRedis;
|
||||
private $completedExprie = 3600;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob;
|
||||
$this->QueueRedis = QueueRedis::getInstance();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
$rawBody = empty($job->getRawBody()) ? '' : $job->getRawBody();
|
||||
$jobData = empty($rawBody) ? [] : json_decode($rawBody, true);
|
||||
$jobId = empty($jobData['id']) ? 'unknown' : $jobData['id'];
|
||||
|
||||
$this->oQueueJob->log("-----------队列任务开始-----------");
|
||||
$this->oQueueJob->log("当前任务ID: {$jobId}, 尝试次数: {$job->attempts()}");
|
||||
|
||||
$iPArticleId = empty($data['p_article_id']) ? 0 : intval($data['p_article_id']);
|
||||
$iPReferId = empty($data['p_refer_id']) ? 0 : intval($data['p_refer_id']);
|
||||
if (empty($iPArticleId) || empty($iPReferId)) {
|
||||
$this->oQueueJob->log("无效的 p_article_id 或 p_refer_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$sClassName = get_class($this);
|
||||
$sRedisKey = "queue_job:{$sClassName}:{$iPArticleId}:{$iPReferId}";
|
||||
$sRedisValue = uniqid() . '_' . getmypid();
|
||||
if (!$this->oQueueJob->acquireLock($sRedisKey, $sRedisValue, $job)) {
|
||||
return;
|
||||
}
|
||||
|
||||
(new ReferenceDispatchService())->dispatchReferByType($iPReferId);
|
||||
|
||||
$this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie, $sRedisValue);
|
||||
$job->delete();
|
||||
$this->oQueueJob->log("任务执行成功 | 日志ID: {$sRedisKey} | p_refer_id:{$iPReferId}");
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->oQueueJob->handleRetryableException($e, $sRedisKey, $sRedisValue, $job);
|
||||
} catch (\LogicException $e) {
|
||||
$this->oQueueJob->handleNonRetryableException($e, $sRedisKey, $sRedisValue, $job);
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleRetryableException($e, $sRedisKey, $sRedisValue, $job);
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user