feat(retry): add OnRetriesExhausted hook for cleanup actions#670
Open
Br1an67 wants to merge 1 commit intoThreeDotsLabs:masterfrom
Open
feat(retry): add OnRetriesExhausted hook for cleanup actions#670Br1an67 wants to merge 1 commit intoThreeDotsLabs:masterfrom
Br1an67 wants to merge 1 commit intoThreeDotsLabs:masterfrom
Conversation
Add OnRetriesExhausted hook to the Retry middleware that is called when all retry attempts are exhausted. This allows users to perform cleanup actions like sending notifications when a message handler consistently fails after maximum retries.
|
这是来自QQ邮箱的假期自动回复邮件。 您好,我现在有事,无法亲自回复您的邮件。我将在看到邮件的第一时间给您回复。
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #545
Motivation / Background
This PR adds an
OnRetriesExhaustedhook to the Retry middleware, allowing users to execute cleanup actions when all retry attempts are exhausted. This addresses the need for performing actions like sending notifications (e.g., to Discord) or updating database records when a message handler consistently fails after the maximum number of retries.Detail
Added a new optional field
OnRetriesExhaustedto theRetrystruct that accepts a function with signaturefunc(err error, retryNum int). This hook is called when:The hook is NOT called when:
ShouldRetryreturns false (which results in a permanent error)Changes:
OnRetriesExhausted func(err error, retryNum int)field to theRetrystructAlternative approaches considered
Considered naming the hook
OnCleanUpHook(as suggested in the issue), but choseOnRetriesExhaustedto better describe when the hook is triggered - when retries are actually exhausted, not just for general cleanup.Checklist