修改自动推广的相关任务
This commit is contained in:
@@ -1795,58 +1795,6 @@ class EmailClient extends Base
|
|||||||
return jsonSuccess();
|
return jsonSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 队列写入测试:推一条 myTestQueue,并返回 push 返回值 + 与 queueDebug 相同 Redis 下的 LLEN(便于对照 redis-cli)。
|
|
||||||
*/
|
|
||||||
public function mytestQueue()
|
|
||||||
{
|
|
||||||
$queueName = 'myTestQueue';
|
|
||||||
$jobClass = 'app\\api\\job\\myQueue@fire';
|
|
||||||
$data = ['testData' => 1];
|
|
||||||
|
|
||||||
$cfg = Config::get('queue');
|
|
||||||
$connector = isset($cfg['connector']) ? (string)$cfg['connector'] : '';
|
|
||||||
if (stripos($connector, 'sync') !== false) {
|
|
||||||
return jsonError('queue connector is Sync — will not write Redis. Check application/extra/queue.php');
|
|
||||||
}
|
|
||||||
if (!extension_loaded('redis')) {
|
|
||||||
return jsonError('PHP redis extension not loaded — Queue Redis connector cannot run.');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$jobId = Queue::push($jobClass, $data, $queueName);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
return jsonError('Queue::push failed: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 独立连一次 Redis,确认与 PHP-FPM 使用的配置一致且 LIST 长度(避免「以为写了其实没有」)
|
|
||||||
$verify = ['ready_len' => null, 'error' => null];
|
|
||||||
try {
|
|
||||||
$redis = new \Redis();
|
|
||||||
$connectMethod = !empty($cfg['persistent']) ? 'pconnect' : 'connect';
|
|
||||||
$redis->$connectMethod($cfg['host'] ?? '127.0.0.1', $cfg['port'] ?? 6379);
|
|
||||||
if (!empty($cfg['password'])) {
|
|
||||||
$redis->auth($cfg['password']);
|
|
||||||
}
|
|
||||||
$redis->select($cfg['select'] ?? 0);
|
|
||||||
$readyKey = 'queues:' . $queueName;
|
|
||||||
$verify['ready_len'] = (int)$redis->lLen($readyKey);
|
|
||||||
$verify['exists'] = (bool)$redis->exists($readyKey);
|
|
||||||
$verify['ping'] = (string)$redis->ping();
|
|
||||||
$verify['checked_db'] = (int)($cfg['select'] ?? 0);
|
|
||||||
$verify['checked_host'] = (string)($cfg['host'] ?? '127.0.0.1');
|
|
||||||
$verify['checked_port'] = (int)($cfg['port'] ?? 6379);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
$verify['error'] = $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonSuccess([
|
|
||||||
'job_id' => $jobId,
|
|
||||||
'queue' => $queueName,
|
|
||||||
'connector' => $connector,
|
|
||||||
'after_push' => $verify,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 队列调试:查看 Redis 里队列长度(不依赖 redis-cli)。
|
* 队列调试:查看 Redis 里队列长度(不依赖 redis-cli)。
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace app\api\job;
|
|||||||
|
|
||||||
use think\queue\Job;
|
use think\queue\Job;
|
||||||
use app\common\PlagiarismService;
|
use app\common\PlagiarismService;
|
||||||
use app\common\QueueJob;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 队列任务:轮询 Turnitin similarity 状态。
|
* 队列任务:轮询 Turnitin similarity 状态。
|
||||||
@@ -20,37 +19,19 @@ use app\common\QueueJob;
|
|||||||
*/
|
*/
|
||||||
class PlagiarismPoll
|
class PlagiarismPoll
|
||||||
{
|
{
|
||||||
private $oQueueJob;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->oQueueJob = new QueueJob();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fire(Job $job, $data)
|
public function fire(Job $job, $data)
|
||||||
{
|
{
|
||||||
$this->oQueueJob->init($job);
|
|
||||||
|
|
||||||
$checkId = isset($data['check_id']) ? intval($data['check_id']) : 0;
|
$checkId = isset($data['check_id']) ? intval($data['check_id']) : 0;
|
||||||
$attempt = isset($data['attempt']) ? intval($data['attempt']) : 1;
|
$attempt = isset($data['attempt']) ? intval($data['attempt']) : 1;
|
||||||
|
|
||||||
if ($checkId <= 0) {
|
if ($checkId <= 0) {
|
||||||
$this->oQueueJob->log("PlagiarismPoll 无效的 check_id,删除任务");
|
|
||||||
$job->delete();
|
$job->delete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$svc = new PlagiarismService();
|
||||||
try {
|
$svc->runPollStatus($checkId, $attempt);
|
||||||
$svc = new PlagiarismService();
|
$job->delete();
|
||||||
$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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace app\api\job;
|
|||||||
|
|
||||||
use think\queue\Job;
|
use think\queue\Job;
|
||||||
use app\common\PlagiarismService;
|
use app\common\PlagiarismService;
|
||||||
use app\common\QueueJob;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 队列任务:上传论文到 Turnitin + 触发 similarity 检测。
|
* 队列任务:上传论文到 Turnitin + 触发 similarity 检测。
|
||||||
@@ -20,38 +19,17 @@ use app\common\QueueJob;
|
|||||||
*/
|
*/
|
||||||
class PlagiarismRun
|
class PlagiarismRun
|
||||||
{
|
{
|
||||||
private $oQueueJob;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->oQueueJob = new QueueJob();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fire(Job $job, $data)
|
public function fire(Job $job, $data)
|
||||||
{
|
{
|
||||||
$this->oQueueJob->init($job);
|
|
||||||
|
|
||||||
$checkId = isset($data['check_id']) ? intval($data['check_id']) : 0;
|
$checkId = isset($data['check_id']) ? intval($data['check_id']) : 0;
|
||||||
$filePath = isset($data['file_path']) ? (string)$data['file_path'] : '';
|
$filePath = isset($data['file_path']) ? (string)$data['file_path'] : '';
|
||||||
|
|
||||||
if ($checkId <= 0 || $filePath === '') {
|
if ($checkId <= 0 || $filePath === '') {
|
||||||
$this->oQueueJob->log("PlagiarismRun 无效参数 check_id={$checkId} file_path={$filePath},删除任务");
|
|
||||||
$job->delete();
|
$job->delete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$svc = new PlagiarismService();
|
||||||
try {
|
$svc->runUploadAndTrigger($checkId, $filePath);
|
||||||
$svc = new PlagiarismService();
|
$job->delete();
|
||||||
$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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class PlagiarismService
|
|||||||
/**
|
/**
|
||||||
* 报告 PDF 本地保存目录(相对于项目根,永久保留)
|
* 报告 PDF 本地保存目录(相对于项目根,永久保留)
|
||||||
*/
|
*/
|
||||||
const REPORT_DIR = 'runtime/plagiarism';
|
const REPORT_DIR = 'public/plagiarism';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 轮询间隔(秒)。Turnitin 一般 1-5 分钟出结果,30 秒一次比较合适
|
* 轮询间隔(秒)。Turnitin 一般 1-5 分钟出结果,30 秒一次比较合适
|
||||||
|
|||||||
Reference in New Issue
Block a user