修改自动推广的相关任务

This commit is contained in:
wangjinlei
2026-04-24 13:13:06 +08:00
parent 48b2335063
commit e1bf8c0189
8 changed files with 603 additions and 89 deletions

View File

@@ -91,8 +91,8 @@ class ExpertFinder extends Base
public function batchFillCountry(){
$service = new ExpertFinderService();
$chain1 = $service->enqueueNextCountryFill(0, 'FetchExpertCity', '');
$chain2 = $service->enqueueNextCountryFill(0, 'FetchExpertCity1', 'http://125.39.141.154:10002/v1/chat/completions');
// $chain1 = $service->enqueueNextCountryFill(0, 'FetchExpertCity', '');
$chain2 = $service->enqueueNextCountryFill(0, 'FetchExpertCityOne', 'http://125.39.141.154:10002/v1/chat/completions');
$pending = Db::name('expert')
->where('affiliation', '<>', '')
@@ -101,7 +101,7 @@ class ExpertFinder extends Base
->count();
return jsonSuccess([
'chain1_started' => $chain1,
// 'chain1_started' => $chain1,
'chain2_started' => $chain2,
'pending' => $pending,
]);

View File

@@ -6,10 +6,12 @@ use think\queue\Job;
use app\common\PromotionService;
/**
* 队列任务:对单个 promotion_task 执行 prepareTask预生成 subject/body
* 【已废弃 / 兼容保留】
*
* 队列名promotion
* 启动 workerphp think queue:listen --queue promotion
* 旧版 task 级 prepare Job新逻辑请使用 PromotionPrepareTask + PromotionPrepareEmail。
*
* 本类仅为兼容队列中可能遗留的旧 payload接收到旧 job 时转发到新的调度器,
* 保证旧消息不会丢失。新代码不应再 push 此 Job。
*/
class PromotionPrepare
{
@@ -18,18 +20,13 @@ class PromotionPrepare
$taskId = intval(isset($data['task_id']) ? $data['task_id'] : 0);
$service = new PromotionService();
if (!$taskId) {
$job->delete();
return;
}
try {
$result = $service->prepareTask($taskId);
$service->log('[PromotionPrepare] task=' . $taskId
. ' prepared=' . $result['prepared']
. ' failed=' . $result['failed']);
} catch (\Exception $e) {
$service->log('[PromotionPrepare] task=' . $taskId . ' exception=' . $e->getMessage());
if ($taskId > 0) {
try {
$service->enqueuePrepareTask($taskId);
$service->log('[PromotionPrepare][deprecated] forwarded task=' . $taskId . ' -> PromotionPrepareTask');
} catch (\Exception $e) {
$service->log('[PromotionPrepare][deprecated] task=' . $taskId . ' forward_exception=' . $e->getMessage());
}
}
$job->delete();

View File

@@ -0,0 +1,52 @@
<?php
namespace app\api\job;
use think\queue\Job;
use app\common\PromotionService;
/**
* 队列任务:单封邮件 prepare调用 LLM 生成个性化描述 + 渲染模板 + 写入 log
*
* 单个 Job 可能耗时较长LLM 调用 30s 超时),因此使用独立队列 promotion_email
* 多 worker 并行消费即可提升吞吐。
*
* 失败策略:
* - PromotionService::prepareSingleEmail 内部已做兜底LLM 失败回退到配置文案),
* 这里遇到未捕获异常时允许重试一次,超过 3 次直接 delete 避免无限循环。
*
* 队列名promotion_email
* 启动 workerphp think queue:listen --queue promotion_email
*/
class PromotionPrepareEmail
{
public function fire(Job $job, $data)
{
$logId = intval(isset($data['log_id']) ? $data['log_id'] : 0);
$service = new PromotionService();
if (!$logId) {
$job->delete();
return;
}
try {
$result = $service->prepareSingleEmail($logId);
$service->log('[PromotionPrepareEmail] log=' . $logId
. ' code=' . $result['code']
. ' llm_status=' . $result['llm_status']
. ' msg=' . $result['msg']);
$job->delete();
} catch (\Exception $e) {
$service->log('[PromotionPrepareEmail] log=' . $logId
. ' attempts=' . $job->attempts()
. ' exception=' . $e->getMessage());
if ($job->attempts() >= 3) {
$job->delete();
} else {
$job->release(30);
}
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace app\api\job;
use think\queue\Job;
use app\common\PromotionService;
/**
* 队列任务task 级别的 prepare 调度器。
*
* 职责:遍历 task 下待准备的 promotion_email_log
* 将每封邮件拆成一条 PromotionPrepareEmail 推到 promotion_email 队列,
* 以便并行调用 LLM 生成个性化描述。
*
* 队列名promotion
* 启动 workerphp think queue:listen --queue promotion
*/
class PromotionPrepareTask
{
public function fire(Job $job, $data)
{
$taskId = intval(isset($data['task_id']) ? $data['task_id'] : 0);
$service = new PromotionService();
if (!$taskId) {
$job->delete();
return;
}
try {
$result = $service->dispatchPrepareEmails($taskId);
$service->log('[PromotionPrepareTask] task=' . $taskId
. ' dispatched=' . $result['dispatched']
. ' already_done=' . ($result['already_done'] ? 1 : 0)
. (empty($result['error']) ? '' : ' error=' . $result['error']));
} catch (\Exception $e) {
$service->log('[PromotionPrepareTask] task=' . $taskId . ' exception=' . $e->getMessage());
}
$job->delete();
}
}