Files
tougao/application/api/job/FetchExperts.php
2026-05-08 15:38:15 +08:00

38 lines
1.1 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\ExpertFinderService;
/**
* 专家抓取队列任务。
* 注意:此任务推送到队列名 "FetchExperts",必须单独启动 worker 才会执行:
* php think queue:work --queue FetchExperts --sleep=3 --tries=3 --daemon
*
* 单条任务可能耗时较长NCBI 接口翻页 + 写库),常驻 worker 受 wait_timeout 影响,
* 由 QueueJob 在进程超过 6h 或致命 DB 错误时主动 exit(1) 让 supervisor 拉起新进程。
*/
class FetchExperts
{
public function fire(Job $job, $data)
{
$field = isset($data['field']) ? (string)$data['field'] : '';
if ($field === '') {
$job->delete();
return;
}
$service = new ExpertFinderService();
$service->doFetchForField(
$field,
isset($data['source']) ? $data['source'] : 'pubmed',
isset($data['per_page']) ? intval($data['per_page']) : 100,
isset($data['min_year']) ? $data['min_year'] : null
);
$job->delete();
}
}