cachewerk / bref-laravel-bridge

An advanced Laravel integration for Bref, including Octane support.
MIT License
38 stars 8 forks source link

Switch to Laravels own queue worker #13

Closed georgeboot closed 2 years ago

georgeboot commented 2 years ago

This PR adds a more native queue handler. It tries to utilise as many internal Laravel components as possible, to stay as close to the other queue implementations as possible.

It's worth noticing that due to the way Lambda timeouts and SQS's integration with Lambda works, it's probably best to run with a batchSize of 1. If you want a larger batch size, make sure your jobs are designed in such a way that it won't break things if they are run more than once.

This package will add a timeout value (calculated for each job by subtracting a safety margin from the remaining invocation time) that will trigger a job timeout exception if the job is configured to do so.

Configuring a job to raise a failed exception on timeout can be done by adding the following to the job class:

public $failOnTimeout = true;

// or

public function shouldFailOnTimeout()
{
    return true;
}

When is this is set, the handler will catch the timeout, flag the job as failed and push it back onto the queue with it's attempts incremented with 1.

If the above is not set, the worker will not catch the timeout, and after SQS's visibility timeout expires, the job will be retried with the attempts NOT incremented.


Closes #6

Tested by hand using a test project deployed using sls.

tillkruss commented 2 years ago

If the above is not set, the worker will not catch the timeout, and after SQS's visibility timeout expires, the job will be retried with the attempts NOT incremented.

How is this not the framework default?! 🤷‍♂️

georgeboot commented 2 years ago

Jup, good question. We could reverse the behaviour and enable it by default? Would be a better 'out of the box' experience.

tillkruss commented 2 years ago

Jup, good question. We could reverse the behaviour and enable it by default? Would be a better 'out of the box' experience.

Yes please.

georgeboot commented 2 years ago

Yes please.

done