-
Notifications
You must be signed in to change notification settings - Fork 56
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
handler after the function fails more than max_attempts #1257
Comments
I'm not 100% sure I understand your usecase, but it looks like the retry feature. Can you have a look at the doc and tell whether it's relevant, and if not, what you'd need that wouldn't be in there ? |
The retry feature works great, what I would like to act if the task fails also at its last retrial (eg retries 10 times, at the 10th time it says “last_retrial”)
Because we can catch and wrap exceptions for the single runs, but we can’t easily identify if the job as whole (across multiple runs) can’t run after the retrials.
…________________________________
From: Joachim Jablon ***@***.***>
Sent: Wednesday, December 18, 2024 9:16:18 AM
To: procrastinate-org/procrastinate ***@***.***>
Cc: Saro2 Passaro ***@***.***>; Author ***@***.***>
Subject: Re: [procrastinate-org/procrastinate] handler after the function fails more than max_attempts (Issue #1257)
I'm not 100% sure I understand your usecase, but it looks like the retry feature<https://procrastinate.readthedocs.io/en/stable/howto/advanced/retry.html>. Can you have a look at the doc and tell whether it's relevant, and if not, what you'd need that wouldn't be in there ?
—
Reply to this email directly, view it on GitHub<#1257 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BNQ6WDWFITQX4XEU2P42X3D2GF7TFAVCNFSM6AAAAABTZZYRI6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJRGQZTIMBWGE>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Still not sure it's what you want, but: @app.task(retry=10, pass_context=True)
def my_task(job_context: procrastinate.JobContext) -> None:
if job_context.job.attempt == job_context.task.retry.max_attempts:
print("Warning: last attempt!")
if random.random() < 0.9:
raise Exception |
Alternatively, something that would work better with custom retry strategies: @app.task(retry=10, pass_context=True)
def my_task(job_context: procrastinate.JobContext) -> None:
if job_context.task.retry.get_retry_decision(exception=Exception(), job=job_context.job) is None:
print("Warning: last attempt!")
if random.random() < 0.9:
raise Exception (of course, it may depend on the exception you set, as you may retry differently on different exceptions) |
I would like to mark the task as failed in my database and alert the user if the task cannot run after max_attempts.
Is there a way to pass the max_attempts configured in the context?
The text was updated successfully, but these errors were encountered: