修改自动推广的相关任务
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\PromotionService;
|
||||
use app\common\QueueJob;
|
||||
|
||||
/**
|
||||
* 队列任务:task 级别的 prepare 调度器。
|
||||
@@ -12,31 +13,44 @@ use app\common\PromotionService;
|
||||
* 将每封邮件拆成一条 PromotionPrepareEmail 推到 promotion_email 队列,
|
||||
* 以便并行调用 LLM 生成个性化描述。
|
||||
*
|
||||
* 队列名:promotion
|
||||
* 启动 worker:php think queue:listen --queue promotion
|
||||
* 队列名:PromotionPrepareTask
|
||||
*/
|
||||
class PromotionPrepareTask
|
||||
{
|
||||
private $oQueueJob;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
$taskId = intval(isset($data['task_id']) ? $data['task_id'] : 0);
|
||||
$service = new PromotionService();
|
||||
$result = $service->dispatchPrepareEmails($taskId);
|
||||
// if (!$taskId) {
|
||||
// $job->delete();
|
||||
// return;
|
||||
// }
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
// 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());
|
||||
// }
|
||||
$taskId = isset($data['task_id']) ? intval($data['task_id']) : 0;
|
||||
if ($taskId <= 0) {
|
||||
$this->oQueueJob->log("PromotionPrepareTask 无效的 task_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
$job->delete();
|
||||
try {
|
||||
$service = new PromotionService();
|
||||
$result = $service->dispatchPrepareEmails($taskId);
|
||||
|
||||
$dispatched = isset($result['dispatched']) ? $result['dispatched'] : 0;
|
||||
$alreadyDone = isset($result['already_done']) ? $result['already_done'] : 0;
|
||||
$err = isset($result['error']) ? $result['error'] : '';
|
||||
$this->oQueueJob->log("PromotionPrepareTask 完成 | task_id={$taskId} dispatched={$dispatched} already_done={$alreadyDone} error={$err}");
|
||||
|
||||
$job->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "task_id={$taskId}");
|
||||
} catch (\Throwable $e) {
|
||||
$this->oQueueJob->handleException($e, $job, "task_id={$taskId}");
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user