Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CrastyCrap's avatar

Laravel Queue failed

Hey there, While i am testing my application queue every thing was fine for several days but today i got that error

my laravel queue failed and give that error "Illuminate\Queue\MaxAttemptsExceededException: App\Jobs\GoogleSheetUpsertRecordJob has been attempted too many times. in /home/forge/api.artmes.net/vendor/laravel/framework/src/Illuminate/Queue/MaxAttemptsExceededException.php:24

i got that error from laravel horizon dashboard the weirdest thing in that when i looked at the code nothing wrong with it and when i tried to test the queue again and it worked i am trying to figure where is the problem to prevent it from happening again,I deployed my application using laravel forge to make sure that there is nothing go wrong but i dont know if that error belongs to syntax error or server error

0 likes
4 replies
LaryAI's avatar
Level 58

It seems like the GoogleSheetUpsertRecordJob job has exceeded the maximum number of attempts defined for a queued job to be tried before it's considered failed. This can happen for a variety of reasons, such as temporary network issues, errors within the job's code that only occur under certain conditions, or issues with external services (like Google Sheets API in your case).

Here are some steps you can take to diagnose and prevent the issue:

  1. Check the Job's Logic: Make sure that the job's code is robust and handles all possible exceptions. This includes checking for any issues with the Google Sheets API, such as rate limits, authentication errors, or unexpected data formats.

  2. Error Handling: Ensure that you have proper error handling within the job. Catch exceptions that might be thrown and decide if the job should be retried or if it should fail immediately under certain conditions.

  3. Job Retries: Review the job's retry settings. Laravel allows you to specify the number of times a job should be retried before it fails. You can set this in the job class itself using the $tries property.

public $tries = 5; // Number of attempts before failing
  1. Timeouts: Set an appropriate timeout for the job to prevent it from running indefinitely. This can be done using the $timeout property in the job class.
public $timeout = 120; // Job will timeout after 120 seconds
  1. Failed Job Handling: Make sure you have a strategy for handling failed jobs. Laravel allows you to define a failed method within your job class that will be called when a job fails.
public function failed(Exception $exception)
{
    // Handle the failure, log it, send notifications, etc.
}
  1. Logging: Add logging to your job to get more insight into what's happening when the job is processed. Log important steps and any exceptions caught.
\Log::info('Job started.');
try {
    // Job logic...
} catch (Exception $e) {
    \Log::error('Job failed with exception: ' . $e->getMessage());
    throw $e; // Re-throw the exception to let the job fail and retry if necessary
}
  1. Review Horizon Metrics: Since you're using Laravel Horizon, review the metrics and dashboard to see if there are any patterns or specific times when the job tends to fail.

  2. Server Resources: Check your server resources on Laravel Forge. It's possible that the server might be running out of memory or overloading due to too many jobs being processed at once.

  3. External Service Availability: Since your job interacts with Google Sheets, ensure that the service is available and that there are no issues with network connectivity or API changes.

  4. Job Payload: If the job fails intermittently, it might be due to specific data it's processing. Check the job payload for any anomalies.

By following these steps, you should be able to identify the root cause of the issue and implement a solution to prevent it from happening again. Remember that intermittent issues can be difficult to track down, so thorough logging and monitoring are key.

CrastyCrap's avatar

@Snapey I tried to get it but unfortunately i cant find any error recorded in logs

click's avatar

That error is thrown if "the max attempts to complete the job are exceeded" as the name of the exception describes. Looking at your job name GoogleSheetUpsertRecordJob a logical reason why that could have happened is that the google api was temporarily not available and threw an Exception triggering a 'retry' in your job. Nothing to worry about if you manually restart the job and it works again.

Only thing you can think about is to increase the amount of attempts and/or increase the delay between each attempt. See https://laravel.com/docs/11.x/queues#dealing-with-failed-jobs for more details how you can do that.

Please or to participate in this conversation.