Laravel bootcamp 发送通知失败

问题描述 投票:0回答:1

我正在关注 Laravel Bootcamp 教程,但我被困在 notifications & events,因为通知未发送。

我在.env while中保留了默认配置,如下:

MAIL_MAILER=log
MAIL_HOST=localhost
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

如果我理解正确的话,应该直接在

storage/logs/laravel.log
写电子邮件。

但是,如果我使用

php artisan queue:work
启动队列处理,并且发送一个新的 chirp,我会看到事件被触发,但一分钟后它会失败,并且在我看到的日志中

[2024-05-12 10:01:39] local.ERROR: App\Listeners\SendChirpCreatedNotifications has been attempted too many times. {"exception":"[object] (Illuminate\\Queue\\MaxAttemptsExceededException(code: 0): App\\Listeners\\SendChirpCreatedNotifications has been attempted too many times. at /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/MaxAttemptsExceededException.php:24)
[stacktrace]
#0 /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(785): Illuminate\\Queue\\MaxAttemptsExceededException::forJob()
#1 /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(519): Illuminate\\Queue\\Worker->maxAttemptsExceededException()
#2 /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(428): Illuminate\\Queue\\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts()
#3 /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(389): Illuminate\\Queue\\Worker->process()
#4 /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(176): Illuminate\\Queue\\Worker->runJob()
#5 /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(139): Illuminate\\Queue\\Worker->daemon()
#6 /root/chirper/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(122): Illuminate\\Queue\\Console\\WorkCommand->runWorker()
#7 /root/chirper/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#8 /root/chirper/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#9 /root/chirper/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#10 /root/chirper/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#11 /root/chirper/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call()
#12 /root/chirper/vendor/laravel/framework/src/Illuminate/Console/Command.php(212): Illuminate\\Container\\Container->call()
#13 /root/chirper/vendor/symfony/console/Command/Command.php(279): Illuminate\\Console\\Command->execute()
#14 /root/chirper/vendor/laravel/framework/src/Illuminate/Console/Command.php(181): Symfony\\Component\\Console\\Command\\Command->run()
#15 /root/chirper/vendor/symfony/console/Application.php(1049): Illuminate\\Console\\Command->run()
#16 /root/chirper/vendor/symfony/console/Application.php(318): Symfony\\Component\\Console\\Application->doRunCommand()
#17 /root/chirper/vendor/symfony/console/Application.php(169): Symfony\\Component\\Console\\Application->doRun()
#18 /root/chirper/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(196): Symfony\\Component\\Console\\Application->run()
#19 /root/chirper/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1187): Illuminate\\Foundation\\Console\\Kernel->handle()
#20 /root/chirper/artisan(13): Illuminate\\Foundation\\Application->handleCommand()
#21 {main}
"}

这是我在控制台中看到的:

$ php artisan queue:work

   INFO  Processing jobs from the [default] queue.

  2024-05-12 14:33:07 App\Listeners\SendChirpCreatedNotifications ................................................................................. RUNNING
  2024-05-12 14:34:10 App\Listeners\SendChirpCreatedNotifications .............................................................................. 1m 3s FAIL
Killed

我还尝试了其他选项,例如 mailpit 或 mailtrap,但仍然无法使其工作;另外,有时

laravel.log
文件中不会记录任何错误消息。

代码是使用 PHP 8.3 从 WSL 运行的

php laravel notifications laravel-11
1个回答
0
投票

最终我能够通过设置更高的超时来解决问题,通过运行

php artisan queue:work --timeout=120

通过这样做,它开始正常工作,确实第一次需要一分钟多一点,如果我没记错的话,这是默认超时

INFO  Processing jobs from the [default] queue.

2024-05-17 19:12:08 App\Listeners\SendChirpCreatedNotifications ................................................................................. RUNNING
2024-05-17 19:13:54 App\Listeners\SendChirpCreatedNotifications ............................................................................. 1m 45s DONE
2024-05-17 19:25:51 App\Listeners\SendChirpCreatedNotifications ................................................................................. RUNNING
2024-05-17 19:26:22 App\Listeners\SendChirpCreatedNotifications ................................................................................ 31s DONE
2024-05-17 19:27:16 App\Listeners\SendChirpCreatedNotifications ................................................................................. RUNNING
2024-05-17 19:27:38 App\Listeners\SendChirpCreatedNotifications ................................................................................ 21s DONE
2024-05-17 19:30:08 App\Listeners\SendChirpCreatedNotifications ................................................................................. RUNNING
2024-05-17 19:30:32 App\Listeners\SendChirpCreatedNotifications ................................................................................ 23s DONE

后续通知所需的运行时间要少得多,甚至重新启动队列工作也不需要那么多时间来处理第一个通知。

© www.soinside.com 2019 - 2024. All rights reserved.