no message
This commit is contained in:
parent
b2f4fd99bb
commit
72dd2a0278
@ -873,6 +873,105 @@ final class Cron
|
||||
echo Tools::toDateTime(time()) . ' 付费用户过期检测完成' . PHP_EOL;
|
||||
}
|
||||
|
||||
// public static function processEmailQueue(): void
|
||||
// {
|
||||
// $iTimestamp = time();
|
||||
//
|
||||
// while (true) {
|
||||
// // 1. 超时检测
|
||||
// if (time() - $iTimestamp > 299) {
|
||||
// echo "邮件队列处理超时,已跳过" . PHP_EOL;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// // 2. 核心:悲观锁取一条并立刻删除(不在发信逻辑内回滚删除)
|
||||
// $oTask = DB::transaction(function () {
|
||||
// $oRaw = DB::selectOne('SELECT * FROM email_queue WHERE `type` IS NULL LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
// if ($oRaw) {
|
||||
// DB::delete('DELETE FROM email_queue WHERE id = ?', [$oRaw->id]);
|
||||
// }
|
||||
// return $oRaw;
|
||||
// });
|
||||
//
|
||||
// if (!$oTask) {
|
||||
// break; // 队列空了
|
||||
// }
|
||||
//
|
||||
// echo '正在发送邮件至: ' . $oTask->to_email . PHP_EOL;
|
||||
//
|
||||
// if (!Tools::isEmail($oTask->to_email)) {
|
||||
// echo $oTask->to_email . ' 格式错误' . PHP_EOL;
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // 3. 执行发信 (放在事务外部)
|
||||
// try {
|
||||
// MailHub::start()
|
||||
// ->setScene($oTask->scene ?? '') // 刚才加的字段派上用场了
|
||||
// ->setTitle($oTask->subject)
|
||||
// ->setView($oTask->template, json_decode($oTask->array, true)) // 注意第二个参数传true转数组
|
||||
// ->setTo($oTask->to_email)
|
||||
// ->send();
|
||||
// } catch (\Throwable $e) {
|
||||
// // 仅打印错误,不影响队列继续处理下一条
|
||||
// echo "发送失败: " . $e->getMessage() . PHP_EOL;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// echo "队列处理完成。" . PHP_EOL;
|
||||
// }
|
||||
|
||||
// public static function processEmailQueue_origin(): void
|
||||
// {
|
||||
// if ((new EmailQueue())->count() === 0) {
|
||||
// echo Tools::toDateTime(time()) . ' 邮件队列为空' . PHP_EOL;
|
||||
// } else {
|
||||
// //记录当前时间戳
|
||||
// $timestamp = time();
|
||||
// //邮件队列处理
|
||||
// while (true) {
|
||||
// if (time() - $timestamp > 299) {
|
||||
// echo Tools::toDateTime(time()) . '邮件队列处理超时,已跳过' . PHP_EOL;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// DB::beginTransaction();
|
||||
// $email_queues_raw = DB::select('SELECT * FROM email_queue where `type` is NULL LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
//
|
||||
// if (count($email_queues_raw) === 0) {
|
||||
// DB::commit();
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// $email_queues = array_map(static function ($value) {
|
||||
// return (array) $value;
|
||||
// }, $email_queues_raw);
|
||||
// $email_queue = $email_queues[0];
|
||||
// echo '发送邮件至 ' . $email_queue['to_email'] . PHP_EOL;
|
||||
// DB::delete('DELETE FROM email_queue WHERE id = ?', [$email_queue['id']]);
|
||||
//
|
||||
// if (Tools::isEmail($email_queue['to_email'])) {
|
||||
// try {
|
||||
// Mail::send(
|
||||
// $email_queue['to_email'],
|
||||
// $email_queue['subject'],
|
||||
// $email_queue['template'],
|
||||
// json_decode($email_queue['array'])
|
||||
// );
|
||||
// } catch (Exception|ClientExceptionInterface $e) {
|
||||
// echo $e->getMessage();
|
||||
// }
|
||||
// } else {
|
||||
// echo $email_queue['to_email'] . ' 邮箱格式错误,已跳过' . PHP_EOL;
|
||||
// }
|
||||
//
|
||||
// DB::commit();
|
||||
// }
|
||||
//
|
||||
// echo Tools::toDateTime(time()) . ' 邮件队列处理完成' . PHP_EOL;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 邮件队列处理
|
||||
public static function processEmailQueue(): void
|
||||
{
|
||||
@ -889,42 +988,35 @@ final class Cron
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
|
||||
$email_queues_raw = DB::select('SELECT * FROM email_queue where `type` is NULL LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
|
||||
if (count($email_queues_raw) === 0) {
|
||||
DB::commit();
|
||||
break;
|
||||
}
|
||||
$email_queues_raw = DB::select('SELECT * FROM email_queue where `type` is NULL LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
|
||||
$email_queues = array_map(static function ($value) {
|
||||
return (array) $value;
|
||||
}, $email_queues_raw);
|
||||
$email_queue = $email_queues[0];
|
||||
echo '发送邮件至 ' . $email_queue['to_email'] . PHP_EOL;
|
||||
DB::delete('DELETE FROM email_queue WHERE id = ?', [$email_queue['id']]);
|
||||
|
||||
if (Tools::isEmail($email_queue['to_email'])) {
|
||||
|
||||
MailHub::start()
|
||||
->setScene($email_queue['scene'])
|
||||
->setTitle($email_queue['subject'])
|
||||
->setView($email_queue['template'], json_decode($email_queue['array']))
|
||||
->setTo($email_queue['to_email'])
|
||||
->send();
|
||||
|
||||
} else {
|
||||
echo $email_queue['to_email'] . ' 邮箱格式错误,已跳过' . PHP_EOL;
|
||||
}
|
||||
|
||||
if (count($email_queues_raw) === 0) {
|
||||
DB::commit();
|
||||
|
||||
} catch (Exception|ClientExceptionInterface $e) {
|
||||
echo $e->getMessage();
|
||||
// DB::rollBack();
|
||||
break;
|
||||
}
|
||||
|
||||
$email_queues = array_map(static function ($value) {
|
||||
return (array) $value;
|
||||
}, $email_queues_raw);
|
||||
$email_queue = $email_queues[0];
|
||||
echo '发送邮件至 ' . $email_queue['to_email'] . PHP_EOL;
|
||||
DB::delete('DELETE FROM email_queue WHERE id = ?', [$email_queue['id']]);
|
||||
|
||||
if (Tools::isEmail($email_queue['to_email'])) {
|
||||
|
||||
MailHub::start()
|
||||
->setScene($email_queue['scene'])
|
||||
->setTitle($email_queue['subject'])
|
||||
->setView($email_queue['template'], json_decode($email_queue['array']))
|
||||
->setTo($email_queue['to_email'])
|
||||
->send();
|
||||
|
||||
} else {
|
||||
echo $email_queue['to_email'] . ' 邮箱格式错误,已跳过' . PHP_EOL;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
}
|
||||
|
||||
@ -956,40 +1048,39 @@ final class Cron
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$sDate = date("Y-m-d");
|
||||
$aSmtp = DB::select('SELECT * FROM smtp_list WHERE `day_clear_date` != "'.$sDate.'" AND `day_count` < `day_max` ORDER BY `day_clear_date` ASC LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
$sDate = date("Y-m-d");
|
||||
$aSmtp = DB::select('SELECT * FROM smtp_list WHERE `day_clear_date` != "'.$sDate.'" AND `day_count` < `day_max` ORDER BY `day_clear_date` ASC LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
|
||||
if (empty($aSmtp) || !isset($aSmtp[0])) {
|
||||
echo Tools::toDateTime(time()) . ' 今日以没有可用smtp' . PHP_EOL;
|
||||
DB::commit();
|
||||
break;
|
||||
}
|
||||
$oSmtp = $aSmtp[0];
|
||||
if (empty($aSmtp) || !isset($aSmtp[0])) {
|
||||
echo Tools::toDateTime(time()) . ' 今日以没有可用smtp' . PHP_EOL;
|
||||
DB::commit();
|
||||
break;
|
||||
}
|
||||
$oSmtp = $aSmtp[0];
|
||||
|
||||
$email_queues_raw = DB::select('SELECT * FROM email_queue where `type` = "bulk" LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
|
||||
if (count($email_queues_raw) === 0) {
|
||||
DB::commit();
|
||||
break;
|
||||
}
|
||||
|
||||
$email_queues = array_map(static function ($value) {
|
||||
return (array) $value;
|
||||
}, $email_queues_raw);
|
||||
$email_queue = $email_queues[0];
|
||||
echo '发送邮件至 ' . $email_queue['to_email'] . PHP_EOL;
|
||||
DB::delete('DELETE FROM email_queue WHERE id = ?', [$email_queue['id']]);
|
||||
|
||||
if (Tools::isEmail($email_queue['to_email'])) {
|
||||
|
||||
MailHub::start()
|
||||
->setScene($email_queue['scene'])
|
||||
->setTitle($email_queue['subject'])
|
||||
->setView($email_queue['template'], json_decode($email_queue['array']))
|
||||
->setTo($email_queue['to_email'])
|
||||
->send();
|
||||
|
||||
$email_queues_raw = DB::select('SELECT * FROM email_queue where `type` = "bulk" LIMIT 1 FOR UPDATE SKIP LOCKED');
|
||||
|
||||
if (count($email_queues_raw) === 0) {
|
||||
DB::commit();
|
||||
break;
|
||||
}
|
||||
|
||||
$email_queues = array_map(static function ($value) {
|
||||
return (array) $value;
|
||||
}, $email_queues_raw);
|
||||
$email_queue = $email_queues[0];
|
||||
echo '发送邮件至 ' . $email_queue['to_email'] . PHP_EOL;
|
||||
DB::delete('DELETE FROM email_queue WHERE id = ?', [$email_queue['id']]);
|
||||
|
||||
if (Tools::isEmail($email_queue['to_email'])) {
|
||||
|
||||
MailHub::start()
|
||||
->setScene($email_queue['scene'])
|
||||
->setTitle($email_queue['subject'])
|
||||
->setView($email_queue['template'], json_decode($email_queue['array']))
|
||||
->setTo($email_queue['to_email'])
|
||||
->send();
|
||||
|
||||
// Mail::send_bulk(
|
||||
// $email_queue['to_email'],
|
||||
// $email_queue['subject'],
|
||||
@ -997,19 +1088,15 @@ final class Cron
|
||||
// json_decode($email_queue['array']),
|
||||
// $oSmtp
|
||||
// );
|
||||
|
||||
DB::update("UPDATE smtp_list SET `day_count` = `day_count` + 1 WHERE id = ".$oSmtp->id);
|
||||
|
||||
|
||||
} else {
|
||||
echo $email_queue['to_email'] . ' 邮箱格式错误,已跳过' . PHP_EOL;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
DB::update("UPDATE smtp_list SET `day_count` = `day_count` + 1 WHERE id = ".$oSmtp->id);
|
||||
|
||||
|
||||
} catch (Exception|ClientExceptionInterface $e) {
|
||||
echo $e->getMessage();
|
||||
} else {
|
||||
echo $email_queue['to_email'] . ' 邮箱格式错误,已跳过' . PHP_EOL;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user