我有一份可以在本地完美工作的工作,但是在生产中我遇到了无法正常工作的问题。我已经将整个handle()
包含在try/catch
中,尽管部署了许多其他例外,但我没有看到任何记录到Bugsnag的信息。
public function handle() {
try {
// do stuff
} catch (\Exception $e) {
Bugsnag::notifyException($e);
throw $e;
}
}
根据Laravel Horizon,此队列作业运行了0.0026001930236816406
秒,我从没见过它,也没有看到failed_jobs
表中与此作业有关的任何其他错误。
config / queue.php
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => (60 * 10), // 10 minutes
'block_for' => null,
],
config / horizon.php
'environments' => [
'production' => [
'supervisor' => [
'connection' => 'redis',
'queue' => [
'default',
],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
// 10 seconds under the queue's retry_after to avoid overlap
'timeout' => (60 * 10) - 10, // Just under 10 mins
],
如果某种原因导致该作业反复重试,我该如何查找?我很茫然。
到目前为止的调查
SELECT DISTINCT exception, COUNT(id) as errors
FROM failed_jobs
WHERE payload LIKE '%[TAG-JOB-HAS]%'
GROUP BY exception;
要查看除此错误消息以外的内容:
工作尝试过多或运行太久
但这就是我所看到的。
答案 0 :(得分:6)
尝试在laravel给出的失败方法中捕获异常
/** * The job failed to process. * * @param Exception $exception * @return void */ public function failed(Exception $exception) { // Send user notification of failure, etc... }
,然后检查本地的默认队列驱动程序是否同步,然后同步其预期的行为
答案 1 :(得分:3)
根据documentation,您可以通过两种常见方式处理作业失败:
DOM
方法。在第一种情况下,您可以使用failed()
方法处理所有作业。您将收到Queue::failing
事件作为参数,并且其中包含异常。
在其他情况下,可以使用Illuminate\Queue\Events\JobFailed
方法,应将其放在failed()
方法附近。您也可以将handle()
作为参数。
示例:
Exception $exception
希望这会有所帮助。
答案 2 :(得分:0)
我遇到了同样的问题
我通过增加'retry_after'参数来修复了该问题
确保retry_after值大于作业运行所需的时间
在 config / queue.php 文件中
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 9000,
],