This commit is contained in:
wangjinlei
2026-04-17 09:51:09 +08:00
parent e9a354c663
commit 4417a7ea28
5 changed files with 314 additions and 41 deletions

View File

@@ -7,33 +7,31 @@ use app\common\ExpertFinderService;
/**
* 队列任务:用本地大模型从 affiliation 推断国家,写入 expert.country_id / country。
* 处理完当前专家后,自动找下一个推入队列(链式执行),直到全部处理完。
* 处理完当前专家后,自动找下一个推入同一队列(链式执行),直到全部处理完。
*
* 队列名FetchExperts
* 启动 workerphp think queue:listen --queue FetchExperts
* 支持多队列并行:通过 $data['queue'] 和 $data['chat_url'] 区分不同的链/模型。
*/
class FillExpertCountry
{
public function fire(Job $job, $data)
{
$expertId = intval(isset($data['expert_id']) ? $data['expert_id'] : 0);
$affiliation = isset($data['affiliation']) ? trim((string)$data['affiliation']) : '';
$queue = isset($data['queue']) ? (string)$data['queue'] : 'FetchExperts';
$chatUrl = isset($data['chat_url']) ? (string)$data['chat_url'] : '';
$service = new ExpertFinderService();
if ($expertId && $affiliation !== '') {
try {
$service->fillExpertCountry($expertId, $affiliation);
$service->fillExpertCountry($expertId, $affiliation, $chatUrl);
} catch (\Exception $e) {
$service->log('[FillExpertCountry] expert_id=' . $expertId . ' exception=' . $e->getMessage());
$service->log('[FillExpertCountry] expert_id=' . $expertId . ' queue=' . $queue . ' exception=' . $e->getMessage());
}
}
$job->delete();
$service->enqueueNextCountryFill(1);
$service->enqueueNextCountryFill(1, $queue, $chatUrl);
}
}