修改自动推广的相关任务

This commit is contained in:
wangjinlei
2026-05-07 11:45:55 +08:00
parent a68742d2c2
commit b1e978ed73
7 changed files with 1221 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace app\api\job;
use think\queue\Job;
use app\common\PlagiarismService;
use app\common\QueueJob;
/**
* 队列任务:轮询 Turnitin similarity 状态。
*
* 未完成会再次入队(链式延迟),完成后下载 PDF 报告并写本地永久保留。
*
* data:
* - check_id t_plagiarism_check.check_id
* - attempt 当前轮询次数(首次为 1
*
* 注意:单条 job 通常很短1 个 HTTP 请求),但会反复入队,常驻 worker 长时间运行
* 由 QueueJob 在进程超 6h 或致命 DB 错误时主动 exit(1) 让 supervisor 拉起新进程。
*/
class PlagiarismPoll
{
private $oQueueJob;
public function __construct()
{
$this->oQueueJob = new QueueJob();
}
public function fire(Job $job, $data)
{
$this->oQueueJob->init($job);
$checkId = isset($data['check_id']) ? intval($data['check_id']) : 0;
$attempt = isset($data['attempt']) ? intval($data['attempt']) : 1;
if ($checkId <= 0) {
$this->oQueueJob->log("PlagiarismPoll 无效的 check_id删除任务");
$job->delete();
return;
}
try {
$svc = new PlagiarismService();
$svc->runPollStatus($checkId, $attempt);
$this->oQueueJob->log("PlagiarismPoll 完成一次轮询 | check_id={$checkId} attempt={$attempt}");
$job->delete();
} catch (\Exception $e) {
$this->oQueueJob->handleException($e, $job, "check_id={$checkId} attempt={$attempt}");
} catch (\Throwable $e) {
$this->oQueueJob->handleException($e, $job, "check_id={$checkId} attempt={$attempt}");
} finally {
$this->oQueueJob->finnal();
}
}
}