laravel-bridge
laravel-bridge copied to clipboard
Cannot get current attempt
Is there any way to find out how often a job already failed, inside the job?
For example: If I configure the queue like in the example with maxReceiveCount: 3
, I would like to know if the current execution is the first or the last job execution.
Especially knowing if it is the last execution is important, because I would like to send a notification to the developers only the last time.
The failed
function inside of a job would be perfect for that, but as far as I understand this does not work with this package.
Is there any solution to this problem or am I missing something?
@korridor Couldn't you setup a dead-letter queue that passed on the dead jobs to another Lambda function that use typed events to locate this specific event type and create the notification?
Especially knowing if it is the last execution is important, because I would like to send a notification to the developers only the last time.
Indeed, if your goal is to alert after retrying, using a dead letter queue is the best solution. You can even set up email alerts via SNS without writing code, I documented that on my blog recently: https://mnapoli.fr/sqs-dead-letter-queue-alarm/
This is a Laravel thing. In Vapor, they just re-create the job and store the current atempt in the job payload: https://github.com/laravel/framework/issues/35444
@mnapoli @danniehansen I could use a dead-letter queue, but this way a few Laravel internal functionalities would not work. For example, as stated here in Laravel documentation the failed
function should be called after all retries have failed. This would not work with a dead-letter queue. In Laravel it is also possible to define the number of attempts per job in the class that describes the job. (https://laravel.com/docs/8.x/queues#max-attempts) This also does not work if Laravel does not know which attempt it is dealing with. I know a could create a SQS queue for each maxReceiveCount
variation that we need, but I would like to know if it is possible to do this without changing the standard behaviour of Laravel. As @georgeboot said Vapor found a way to do this and there is also this laravel plugin (https://github.com/christoph-kluge/bref-sqs-laravel) that apparently made this work.
See #28