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

Cannot get current attempt #14

Open
korridor opened this issue Sep 17, 2020 · 5 comments
Open

Cannot get current attempt #14

korridor opened this issue Sep 17, 2020 · 5 comments

Comments

@korridor
Copy link

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?

@danniehansen
Copy link

@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?

@mnapoli
Copy link
Member

mnapoli commented Oct 16, 2020

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/

@georgeboot
Copy link
Contributor

This is a Laravel thing. In Vapor, they just re-create the job and store the current atempt in the job payload: laravel/framework#35444

@korridor
Copy link
Author

@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.

@georgeboot
Copy link
Contributor

See #28

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