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

55 lines
1.6 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;
/**
* 队列任务:发送 task 下"已 prepare"的邮件,按 min/max_interval 控制节奏。
*
* processNextEmail 内部会自动把下一封邮件 later() 入队(链式延迟),
* 因此本 job 处理完一封即可 delete无需在这里再 dispatch 下一封。
*
* 队列名PromotionSend
*/
class PromotionSend
{
private $oQueueJob;
public function __construct()
{
$this->oQueueJob = new QueueJob();
}
public function fire(Job $job, $data)
{
$this->oQueueJob->init($job);
$taskId = isset($data['task_id']) ? intval($data['task_id']) : 0;
if ($taskId <= 0) {
$this->oQueueJob->log("PromotionSend 无效的 task_id删除任务");
$job->delete();
return;
}
try {
$service = new PromotionService();
$result = $service->processNextEmail($taskId);
$done = !empty($result['done']) ? 1 : 0;
$reason = isset($result['reason']) ? $result['reason'] : '';
$this->oQueueJob->log("PromotionSend 完成 | task_id={$taskId} done={$done} reason={$reason}");
$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();
}
}
}