-
Notifications
You must be signed in to change notification settings - Fork 402
Adds retry mechanism to applyNullSafe method #204
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import javax.annotation.CheckForNull; | ||
| import javax.annotation.Nonnull; | ||
| import java.io.IOException; | ||
| import java.net.UnknownHostException; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
|
|
@@ -64,6 +65,9 @@ public class GitHubRepositoryName { | |
| Pattern.compile("ssh://(?:git@)?([^/]+)/([^/]+)/([^/]+)/?") | ||
| }; | ||
|
|
||
| private static final int MAX_RETRIES = 3; | ||
| private static final int BACKOFF_MILLIS = 50; | ||
|
|
||
| /** | ||
| * Create {@link GitHubRepositoryName} from URL | ||
| * | ||
|
|
@@ -223,12 +227,25 @@ private static Function<GitHub, GHRepository> toGHRepository(final GitHubReposit | |
| return new NullSafeFunction<GitHub, GHRepository>() { | ||
| @Override | ||
| protected GHRepository applyNullSafe(@Nonnull GitHub gitHub) { | ||
| try { | ||
| return gitHub.getRepository(format("%s/%s", repoName.getUserName(), repoName.getRepositoryName())); | ||
| } catch (IOException e) { | ||
| LOGGER.warn("Failed to obtain repository {}", this, e); | ||
| return null; | ||
| int mtries = 0; | ||
| while (mtries < MAX_RETRIES) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some @annotation oriented retry mechanism in the project? Otherwise, can we look for some utility class/create one? |
||
| try { | ||
| return gitHub.getRepository(format("%s/%s", repoName.getUserName(), | ||
| repoName.getRepositoryName())); | ||
| } catch (UnknownHostException e) { | ||
| LOGGER.warn("Failed to resolve repository {}", this, e); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this code covered by a unit test? |
||
| mtries++; | ||
| try { | ||
| Thread.sleep(BACKOFF_MILLIS * mtries); | ||
| } catch (InterruptedException ex) { | ||
| LOGGER.error("{}", this, ex); | ||
| } | ||
| } catch (IOException e) { | ||
| LOGGER.warn("Failed to obtain repository {}", this, e); | ||
| return null; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
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.
Should we do this in a separate PR?
Or is it necessary for the fix?
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.
It is not necessary for this fix. I added it because I don't think it hurts, but it can be moved to a separate PR, or even not changed if there is any reason to keep it to 3.0.2.
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.
Just about the atomicity of the commits.