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

add functionality to annotation to allow a spel expressions #34

Closed
scottmf opened this issue Dec 16, 2015 · 12 comments
Closed

add functionality to annotation to allow a spel expressions #34

scottmf opened this issue Dec 16, 2015 · 12 comments
Milestone

Comments

@scottmf
Copy link

scottmf commented Dec 16, 2015

It would be very useful if the @retryable annotation allowed an expression using spel to have an easy way to further inspect an exception in order to determine if a retry should occur.

For example:

@Retryable(include=HttpClientErrorException.class, retryOn="#result.getHttpStatus().value() == 401")
public void runExchange() { ... }
@garyrussell
Copy link
Contributor

You could do that relatively easily today with

@Retryable(interceptor="myInterceptor")

Where myInterceptor is a RetryOperationsInterceptor bean with a custom retry policy that looks at the exception to decide in canRetry().

@scottmf
Copy link
Author

scottmf commented Dec 16, 2015

thanks Gary. I know the interceptor is available but in the spirit of conciseness it would be nice to have a spel expression

@garyrussell
Copy link
Contributor

It's probably not too hard for a single exception, but the include attribute is an array, and no include means retry for all exceptions. The expression might get unruly very quickly...

"#this instanceof T(com.Foo) ? #this.somCondition() : #this instanceof T(com.Bar) ? #this.someOtherCondition() : false"

I am happy to discuss further, though.

@scottmf
Copy link
Author

scottmf commented Dec 16, 2015

Understood. I would think that for more complex situations a developer would create an interceptor and for simple situations like mine it would be nice not to have to add all the extra boiler plate. I see a lot of annotations using spel like this and situations can occur like you suggested, but for ~ 80% of the scenarios it is very clean.

I have need for the interceptor right now so that's what I am going to use. If you strongly feel that the expression is the wrong thing to do then that's fine. As a consumer of the api, who uses it a lot, it would be a nice feature to add.

garyrussell added a commit to garyrussell/spring-retry that referenced this issue Dec 16, 2015
@garyrussell
Copy link
Contributor

I just hacked together a quick PoC garyrussell@f2c98b7

Let's see what @dsyer thinks about whether it's worth pursuing.

@shollander
Copy link

shollander commented Nov 30, 2016

Hi,
This feature would be very useful for me as well. Any word on getting the fix by @garyrussell incorporated into a release?

What I am really looking for is a way to configure the maxAttempts and Backoff parameters so that they are configurable and not hard-coded at compile time.

@dsyer
Copy link
Member

dsyer commented Nov 30, 2016

I didn't see this until now. Maybe a PR would help?

@richiep33
Copy link

I am very interested in this feature as well. I have considered writing my own due to this limitation. Otherwise, spring-retry appears very useful.

@garyrussell
Copy link
Contributor

The PoC just evaluates an expression against the exception to decide whether it was retryable or not (which is the original request in this issue).

It does not address evaluating the maxAttempts and backOff attributes as expressions; that's really a separate issue and would take a bit more work.

I am offsite all next week so I don't think I could look at this before Dec 12 which might be too late for spring-retry 1.2. I'll see if I can spring free some time tomorrow, but no promises.

garyrussell added a commit to garyrussell/spring-retry that referenced this issue Dec 1, 2016
garyrussell added a commit to garyrussell/spring-retry that referenced this issue Dec 1, 2016
garyrussell added a commit to garyrussell/spring-retry that referenced this issue Dec 1, 2016
@garyrussell
Copy link
Contributor

I went ahead and issued a PR; not sure if we feel it's too big to add to 1.2 after the RC.

I went with discrete attributes to avoid breaking changes.

@dsyer dsyer closed this as completed in #66 Dec 1, 2016
@dsyer dsyer added this to the 1.2.0 milestone Dec 1, 2016
garyrussell added a commit to garyrussell/spring-retry that referenced this issue Dec 1, 2016
@shollander
Copy link

Thanks for the quick action on this. I tried out the snapshot build and it works perfectly - just what we needed!

@garyrussell
Copy link
Contributor

@dsyer Please note I submitted another PR.

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

No branches or pull requests

5 participants