Files
tougao/application/api/job/PlagiarismRun.php
2026-05-07 11:45:55 +08:00

58 lines
1.8 KiB
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;
use app\common\QueueJob;
/**
* 队列任务:上传论文到 Turnitin + 触发 similarity 检测。
*
* 完成后会自动入队 PlagiarismPoll 进行后续轮询。
*
* data:
* - check_id t_plagiarism_check.check_id
* - file_path 本地可读的 PDF/DOCX 绝对路径
*
* 注意:上传单个 PDF 可能耗时数十秒,常驻 worker 由 QueueJob 在进程超 6h 或致命 DB
* 错误时主动 exit(1) 让 supervisor 拉起新进程。
*/
class PlagiarismRun
{
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;
$filePath = isset($data['file_path']) ? (string)$data['file_path'] : '';
if ($checkId <= 0 || $filePath === '') {
$this->oQueueJob->log("PlagiarismRun 无效参数 check_id={$checkId} file_path={$filePath},删除任务");
$job->delete();
return;
}
try {
$svc = new PlagiarismService();
$svc->runUploadAndTrigger($checkId, $filePath);
$this->oQueueJob->log("PlagiarismRun 完成 | check_id={$checkId}");
$job->delete();
} catch (\Exception $e) {
// PlagiarismService 内部已经把状态置为 failed致命 DB 错误下 handleException 会 exit(1)
$this->oQueueJob->handleException($e, $job, "check_id={$checkId}");
} catch (\Throwable $e) {
$this->oQueueJob->handleException($e, $job, "check_id={$checkId}");
} finally {
$this->oQueueJob->finnal();
}
}
}