Skip to content

Add Retry annotation #139

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

Merged
merged 9 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
<version>1.4.1-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.microsoft.maven</groupId>
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/microsoft/azure/functions/annotation/Retry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.functions.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* <p>
* Defines Retry Policy</p>
*
* @since 1.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Retry {
/**
* The strategy of retry
* @return The retry strategy
*/
RetryStrategy strategy();
/**
* The maximum number of retries that will be attempted.
* @return The maximum retry count.
*/
int maxRetryCount();
/**
* The minimum delay interval.
* @return The minimum retry delay.
*/
String minimumInterval() default "";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use integer here and set the interval in second directly? which may be more clear and no need to care about the format. Otherwise, do we support time string like 00:00:120?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats a good point! minimumInterval, maximumInterval and delayInterval get converted to type TimeSpan , is there an equivalent in Java?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duration?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if converting Duration to string will give us the format hh:mm:ss

Copy link
Collaborator Author

@TsuyoshiUshio TsuyoshiUshio Nov 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it. There is an api to fetch it as second. However, I'm not sure Duration is good fit for the annotation. Probably String (as is) or int (second) might be a good fit for it. (I just reply the TimeSpan equivalent) https://www.dariawan.com/tutorials/java/java-time-duration-tutorial-examples/
Hi @Flanker32 Which would you want to prefer? If you choose int, you need to format String. If you use String, no need to convert it since it is the format of function.json IMO, String might be better. the reason is, Functions Host currently support String with that format. In the future, if people add expression on the String on the functions host side, we need to do breaking change. What do you think?

/**
* The maximum delay interval.
* @return The maximum retry delay.
*/
String maximumInterval() default "";
/**
* The delay between retries.
* @return The delay interval.
*/
String delayInterval() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.functions.annotation;

/**
* <p>
* Strategy of the Retry annotation. Choose 'EXPONENTIAL' if you use the exponential back off strategy or 'FIXED'
* if you use the fixed delay strategy. For more details, refer to https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-error-pages?tabs=csharp#function-level-configuration .
* </p>
*
* @since 1.0.0
*/
public enum RetryStrategy {
/**
* Defines an exponential backoff retry strategy, where the delay between retries
* will get progressively larger, limited by the max/min specified.
*/
EXPONENTIAL,
/**
* Defines a retry strategy where a fixed delay is used between retries.
*/
FIXED;
}