修改自动推广的相关任务

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,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();
}
}