Files
tougao/application/api/job/PromotionPrepareEmail.php
2026-05-07 11:45:40 +08:00

59 lines
2.0 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\PromotionService;
use app\common\QueueJob;
/**
* 队列任务:单封邮件 prepare调用 LLM 生成个性化描述 + 渲染模板 + 写入 log
*
* 单条 job 可能耗时 30s+LLM 调用)。常驻 worker 必须配合 supervisor 守护,
* 当进程超过 6h 或遇到致命 DB 错误时QueueJob 会主动 exit(1),由 supervisor 拉起新进程,
* 避开 MySQL wait_timeout 把连接关掉后所有任务持续 fail 的问题。
*
* 启动建议:
* php think queue:work --queue PromotionPrepareEmail --sleep=3 --tries=3 --daemon
*/
class PromotionPrepareEmail
{
// private $oQueueJob;
// public function __construct()
// {
// $this->oQueueJob = new QueueJob();
// }
public function fire(Job $job, $data)
{
// $this->oQueueJob->init($job);
//
$logId = isset($data['log_id']) ? intval($data['log_id']) : 0;
// if ($logId <= 0) {
// $this->oQueueJob->log("PromotionPrepareEmail 无效的 log_id删除任务");
// $job->delete();
// return;
// }
//
// try {
$service = new PromotionService();
$service->log("id:".$logId);
// $result = $service->prepareSingleEmail($logId);
//
// $code = isset($result['code']) ? $result['code'] : '';
// $msg = isset($result['msg']) ? $result['msg'] : '';
// $llm = isset($result['llm_status']) ? $result['llm_status'] : '';
// $this->oQueueJob->log("PromotionPrepareEmail 完成 | log_id={$logId} code={$code} llm_status={$llm} msg={$msg}");
$job->delete();
// } catch (\Exception $e) {
// $this->oQueueJob->handleException($e, $job, "log_id={$logId}");
// } catch (\Throwable $e) {
// $this->oQueueJob->handleException($e, $job, "log_id={$logId}");
// } finally {
// $this->oQueueJob->finnal();
// }
}
}