在我的应用程序中,用户有可以发送到的电子邮件列表。他们的帐户设置了一天中自动发送电子邮件的时间和所在时区。
我想在全球范围内为碳排放设定一个假时间。
在
public/index.php
,我试图设置:
$time = Carbon::create('2020-09-16 00:00:00');
Carbon::setTestNow($time);
但我的应用程序不受影响。
有没有一种全球性的方法来设定假时间?
在我的应用程序中,用户有可以发送到的电子邮件列表。他们的帐户设置了一天中自动发送电子邮件的时间和所在时区。
在听众内部
handle
方法如下所示:
public function handle(ReviewRequested $event)
{
$time = Carbon::create(2020, 9, 15, 0);
Carbon::setTestNow($time);
$reviewRequest = $event->reviewRequest;
Log::info('email sending at ' . $reviewRequest->sent_at . ' and current time is ' . Carbon::now());
Mail::to($reviewRequest->customer->email)
->later($reviewRequest->sent_at, new ReviewRequestMailer($reviewRequest));
}
请注意,我用碳纤维来伪装时间,并将其设置为午夜。在本例中,电子邮件应该在上午9点发送。记录的信息如下:
local.INFO: email sending at 2020-09-15 09:00:00 and current time is 2020-09-15 00:00:00
所以现在的时间是凌晨12点,我在排队等待9点的邮件。
我一跑
php artisan queue:work
,将立即运行并发送挂起的作业(电子邮件)。为什么会这样?他们应该一直排队到上午9点。
也许排队是在使用系统时间,而不关心我在碳排放中设置了什么?我如何解决这个问题?
我忘了用Redis