Files
tougao/application/api/job/PlagiarismRun.php
2026-05-18 18:34:48 +08:00

41 lines
1.2 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;
/**
* 队列任务:创建 Turnitin submission 并上传原稿ingest 轮询与触发 similarity 由后续 Job 完成。
*
* 链PlagiarismRun → PlagiarismWaitIngest → PlagiarismTriggerSimilarity → PlagiarismPoll
*
* data:
* - check_id t_plagiarism_check.check_id
* - file_path 本地可读的 PDF/DOCX 绝对路径
*
* 注意:上传单个 PDF 可能耗时数十秒,常驻 worker 由 QueueJob 在进程超 6h 或致命 DB
* 错误时主动 exit(1) 让 supervisor 拉起新进程。
*/
class PlagiarismRun
{
public function fire(Job $job, $data)
{
$checkId = isset($data['check_id']) ? intval($data['check_id']) : 0;
$filePath = isset($data['file_path']) ? (string)$data['file_path'] : '';
if ($checkId <= 0 || $filePath === '') {
$job->delete();
return;
}
$svc = new PlagiarismService();
$svc->log('PlagiarismRun job is running');
try {
$svc->runUploadOnly($checkId, $filePath);
} catch (\Throwable $e) {
$svc->markFailed($checkId, '[upload] ' . $e->getMessage());
}
$job->delete();
}
}