#Job queue weird behaviour?

8 messages · Page 1 of 1 (latest)

grave vessel
#

I have a job that queries an external api but wether upon the result of the api the job should be retried later. The thing is that I tried doing $this->release(60); in the handle function of the job to retry it in 60 seconds but the job will always fail with the exception MaximumRetriesExceeded. Why is this?

This is the code I wrote which works, I was wondering why this works and the use of release(60) does not.

/**
     * Execute the job.
     */
    public function handle()
    {
        $client = app()->make(Client::class);

        // Check if the asyonchronous reboot job has finished
        $response = $client->queryAsyncJob($this->jobid, RebootVirtualMachineCommandResponse::class);
        if (false === $response) {
            $this->delete();
            dispatch(new self($this->jobid, $this->vps->id))->delay(60);
            return;

            // Instead of the above lines this is where I had the release(60) call (without the delete)
        }

        $this->vps->performing_action = VpsActionType::NONE;
        $this->vps->save();
    }
thin smelt
#

When a job is dispatched its assigned a timestamp of when it expires and a number of possible retries. So in your original example the job passed the job expiration timestamp. https://laravel.com/docs/10.x/queues#timeout

What you're code is doing is dispatching a completely new job that is delayed by 60 seconds

grave vessel
#
/**
 * The number of seconds to wait before retrying the job.
 *
 * @var int
 */
public int $backoff = 60;

/**
 * Execute the job.
 */
public function handle()
{
    $client = app()->make(Client::class);

    // Check if the asyonchronous reboot job has finished
    $response = $client->queryAsyncJob($this->jobid, RebootVirtualMachineCommandResponse::class);
    if (false === $response) {
        $this->release(60);
        return;
    }

    $this->vps->performing_action = VpsActionType::NONE;
    $this->vps->save();
}

@thin smelt This is the code I had before which gave the result I mentioned. It retries, retries after 60, retries after 60 again and then it just says it failed. However when I immediately execute artisan queue:retry all the job immediately succeeds

thin smelt
#

have you defined the public int $retries?

grave vessel
#

However, what seemed weird to me is that if I included a var_dump('hello!'); at the top of the handle function it only displayed once instead of the expected 3 times but the queue shows 3 attempts in the terminal

#

Yes I have :)

thin smelt
#

try removing the backoff. It may be an issue that your backoff and release are overriding each other