Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job with error (not exception) is retried indefinitely #1524

Open
ariddlestone opened this issue Dec 18, 2024 · 1 comment
Open

Job with error (not exception) is retried indefinitely #1524

ariddlestone opened this issue Dec 18, 2024 · 1 comment

Comments

@ariddlestone
Copy link

Horizon Version

5.29.4

Laravel Version

11.34.2

PHP Version

8.3.14

Redis Driver

PhpRedis

Redis Version

6.1.0

Database Driver & Version

mysqlnd 8.3.14

Description

If a job throws an error (not an exception) it seems to just be reprocessed indefinitely, despite the worker output saying it failed.

In contrast, Laravel queue workers fail the job and don't try to reprocess it. It is then visible in the failed jobs list/table.

The actual error which caused this for us was when trying to process a job whose class had been removed from the codebase (we had checked out a different branch while there were still jobs in the queue), but the effect was that we starting filling the Laravel log file at an alarming rate.

Steps To Reproduce

Create a new job:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class ErrorJob implements ShouldQueue
{
    use Dispatchable;
    use Queueable;

    public function handle(): void
    {
        trigger_error('Error triggered in job');
    }
}

Create a command to dispatch it (for convenience):

<?php

namespace App\Console\Commands;

use App\Jobs\ErrorJob;
use Illuminate\Console\Command;

class QueueDummyJobs extends Command
{
    protected $signature = 'app:queue-error-job';

    public function handle(): int
    {
        ErrorJob::dispatch();
        $this->getOutput()->writeln('Job dispatched');
        return self::SUCCESS;
    }
}

Dispatch that job:

$ php artisan app:queue-error-job
Job dispatched

Run the worker:

$ php artisan horizon

   INFO  Horizon started successfully.  

  2024-12-18 16:45:46 App\Jobs\ErrorJob .............................. RUNNING
  2024-12-18 16:45:46 App\Jobs\ErrorJob .......................... 5.75ms FAIL
  2024-12-18 16:45:46 App\Jobs\ErrorJob .............................. RUNNING
  2024-12-18 16:45:46 App\Jobs\ErrorJob .......................... 3.70ms FAIL
  2024-12-18 16:45:46 App\Jobs\ErrorJob .............................. RUNNING
  2024-12-18 16:45:46 App\Jobs\ErrorJob .......................... 5.43ms FAIL
  2024-12-18 16:45:46 App\Jobs\ErrorJob .............................. RUNNING
  2024-12-18 16:45:46 App\Jobs\ErrorJob .......................... 4.14ms FAIL
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants