Files
tougao/application/api/job/PlagiarismPoll.php
2026-05-08 17:59:08 +08:00

38 lines
1019 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\api\job;
use think\queue\Job;
use app\common\PlagiarismService;
/**
* 队列任务:轮询 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
{
public function fire(Job $job, $data)
{
$checkId = isset($data['check_id']) ? intval($data['check_id']) : 0;
$attempt = isset($data['attempt']) ? intval($data['attempt']) : 1;
if ($checkId <= 0) {
$job->delete();
return;
}
$svc = new PlagiarismService();
$svc->runPollStatus($checkId, $attempt);
$job->delete();
}
}