致任何使用 Laravel Jobs 和 Horizon 的人。有时,作业成功后,队列会毫无理由地再次尝试:
App\Jobs\Job has been attempted too many times. {"exception":"[object] (Illuminate\\Queue\\MaxAttemptsExceededException(code: 0): App\\Jobs\\Job has been attempted too many times. at /vendor/laravel/framework/src/Illuminate/Queue/MaxAttemptsExceededException.php:24)
我尝试了不同的 Horizon 配置,但这种情况仍在发生。我看到您必须创建
retry_after
参数,但仍然发生。
有人有解决办法吗?我在几个项目中都遇到过这种情况。
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'autoScalingStrategy' => 'time',
'maxProcesses' => 1,
'maxTime' => 0,
'maxJobs' => 0,
'memory' => 256,
'tries' => 1,
'timeout' => 3600,
'nice' => 0,
'retry_after' => 3700,
],
],`
您可以通过声明作业变量直接从作业定义进行配置,例如:
public $tries = 10; //max execution of job will be 10 times
public $retryAfter = 60; // interval for next job is 60 seconds
public $timeout = 1200; // Max execution time is 1200 seconds for this job