-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Support custom delays for automatic retries #931
Conversation
Codecov Report
|
I reconsidered behaviour in case a user code threw exception inside |
What if |
@odinserj You are right, if |
Great @aidmsu! Pay special attention to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't get used to reviews, waiting for EnqueuedState transition on zero delay.
@odinserj I fixed it. |
This feature is nice but you can't define a |
@odinserj / any other admin: Is there an update on whether (and if so when) this will be merged into master and released? Looking at https://github.com/HangfireIO/Hangfire/compare/dev it appears that this has not been released, but I could be wrong. |
Hey @odinserj, any ETA for this feature to be released? Being able to adjust the retry delay times is really useful on some scenarios. Thanks! |
I've created a version of [AutomaticRetryV2(ConfigKey = MyClass.ConfigKey, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
Task MyMethod(long someId);
// In your autofac registration:
builder.Register(cc => new Dictionary<string, AutomaticRetryV2AttributeConfig>
{
{
MyClass.ConfigKey,
new AutomaticRetryV2AttributeConfig
{
DelaysInSeconds = _settings.MyMethodDelayBetweenAttempts.HasValue
? new[] {_settings.MyMethodDelayBetweenAttempts.Value}
: null,
Attempts = _settings.MyMethodRetryAttempts
}
}
})
.As<IDictionary<string, AutomaticRetryV2AttributeConfig>>()
.SingleInstance();
Let me know if anybody's interested, and I'd be happy to create a PR for the attribute update. I'm planning on creating a PR for the required autofac-hangfire filter provider integration in https://github.com/HangfireIO/Hangfire.Autofac before too long. |
* Support custom delays for retries * Specify delayInSeconds as int array * User code errors lead to exception in AutomaticRetryAttribute * Fix DelaysInSeconds property documentation * Remove one empty line * Apply Enqueue state for retry job if delay is zero * Add more tests for AutomaticRetryAttribute * Update AutomaticRetryAttribute tests
Any updates on this? |
It would be very nice if this PR can be included in the next release. |
It's published in 1.7-beta. |
Am I reading this correctly, that there is no way to specify a delay algorithm on a per-job basis? I.e. it's either global, for all jobs, or static? I need to implement an exponential back-off with jitter delay algorithm, but it should only be applied to specific jobs. |
@SimonOrdo I am looking for the same. I think it isn't implemented yet. |
@SimonOrdo , @HristoDimitrovBede did you ever manage to implement an exponential back-off with jitter delay algorithm for specific jobs? |
This PR adds ability to specify custom delays for retries via
AutomaticRetryAttribute
.Specify custom delays by an integer array.
You can set a delay for a job:
Also it's possible set a delay for all jobs:
Specify custom delay by a function.
If you want to use complex algorithm to define a delay by a attempt you should set
AutomaticRetryAttribute.DelayInSecondsByAttemptFunc
property:Behaviour
If you specifty both
DelaysInSeconds
andDelayInSecondsByAttemptFunc
then onlyDelaysInSeconds
will be used.If given
DelayInSecondsByAttemptFunc
throws excecption then the default function will be used.