修改自动推广的相关任务

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

@@ -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);
}
}
}
}