作业尝试次数过多或运行时间过长 [英] Job has been attempted too many times or run too long
问题描述
我有一份可以在本地完美工作的工作,但是在生产中我遇到了无法正常工作的问题.我已经将整个 handle()
包含在 try/catch
中,尽管部署了许多其他异常,但是我看不到任何记录到Bugsnag的东西.
I have a job that works flawless locally, but in production I run into issues where it doesn't work. I've encompassed the entire handle()
with a try/catch
and am not seeing anything logged to Bugsnag, despite many other exceptions elsewhere from being deployed.
public function handle() {
try {
// do stuff
} catch (\Exception $e) {
Bugsnag::notifyException($e);
throw $e;
}
}
根据 Laravel Horizon ,此队列作业的运行时间为 0.0026001930236816406
秒永远不会看到它起作用,并且永远不会在与该工作相关的 failed_jobs
表中看到任何其他错误.
According to Laravel Horizon this queue job runs for 0.0026001930236816406
seconds and I never see it work and never see any other errors in the failed_jobs
table as it relates to this job.
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
],
如果由于某种原因导致该作业一遍又一遍地重试,我该如何查找?我很茫然.
If something is causing this job to retry over and over, how can I find out how? I'm at a loss.
到目前为止的调查
- 我的期望是我应该能够运行查询:
SELECT DISTINCT exception, COUNT(id) as errors
FROM failed_jobs
WHERE payload LIKE '%[TAG-JOB-HAS]%'
GROUP BY exception;
要查看除此错误消息以外的内容:
To see more than this error message:
工作尝试过多或运行太久
Job has been attempted too many times or run too long
但这就是我所看到的.
- Laravel Horizon 的仪表板显示正在运行的工作是<1秒,所以我知道实际上并没有超时.
- Laravel Horizon's dashboard shows the job in question is running for < 1 second, so I know it's not actually timing out.
推荐答案
尝试在laravel给定的失败方法中捕获异常
Try to catch the exception in the failed method given by laravel
/**
* The job failed to process.
*
* @param Exception $exception
* @return void
*/
public function failed(Exception $exception)
{
// Send user notification of failure, etc...
}
,然后检查本地的默认队列驱动程序是否同步,然后同步其预期行为.
and check whether your default queue driver in local is sync then its expected behavior.
这篇关于作业尝试次数过多或运行时间过长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!