Skip to content

Commit d9d4ca9

Browse files
committed
If initial issue update failed with assignee and response points to a problem with it: retry without
1 parent 7f411ae commit d9d4ca9

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/main/java/org/hibernate/infra/replicate/jira/service/jira/JiraService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ public void registerManagementRoutes(@Observes ManagementInterface mi) {
139139
}).schedule();
140140
rc.end();
141141
});
142+
mi.router().get("/sync/issues/re-sync/:project/:issue").blockingHandler(rc -> {
143+
// TODO: we can remove this one once we figure out why POST management does not
144+
// work correctly...
145+
String project = rc.pathParam("project");
146+
String issue = rc.pathParam("issue");
147+
148+
HandlerProjectContext context = contextPerProject.get(project);
149+
150+
if (context == null) {
151+
throw new IllegalArgumentException("Unknown project '%s'".formatted(project));
152+
}
153+
154+
triggerSyncEvent(context.sourceJiraClient().getIssue(issue), context);
155+
rc.end();
156+
});
142157
mi.router().post("/sync/issues/list").consumes(MediaType.APPLICATION_JSON).blockingHandler(rc -> {
143158
// sync issues based on a list of issue-keys supplied in the JSON body:
144159
JsonObject request = rc.body().asJsonObject();

src/main/java/org/hibernate/infra/replicate/jira/service/jira/client/JiraRestClientBuilder.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ private String sanitize(String header, String value) {
122122
}
123123
}
124124

125-
// TODO: remove it once we figure out how to correctly integrate smallrye fault-tolerance
126-
// (simply adding annotations on the REST interface does not work)
125+
// TODO: remove it once we figure out how to correctly integrate smallrye
126+
// fault-tolerance
127+
// (simply adding annotations on the REST interface does not work)
127128
private static class JiraRestClientWithRetry implements JiraRestClient {
128129

129130
private final JiraRestClient delegate;
@@ -155,7 +156,7 @@ public JiraIssueBulkResponse create(JiraIssueBulk bulk) {
155156
@Override
156157
public JiraIssueResponse update(String key, JiraIssue issue) {
157158
// it might be that mapped user is wrong so we don't want to keep sending it
158-
return withRetry( () -> delegate.update( key, issue ), 2 );
159+
return withRetry(() -> delegate.update(key, issue), 2);
159160
}
160161

161162
@Override
@@ -259,7 +260,7 @@ private void withRetry(Runnable runnable) {
259260
}
260261

261262
private <T> T withRetry(Supplier<T> supplier) {
262-
return withRetry( supplier, RETRIES );
263+
return withRetry(supplier, RETRIES);
263264
}
264265

265266
private <T> T withRetry(Supplier<T> supplier, int retries) {
@@ -303,6 +304,13 @@ private boolean shouldRetryOnException(Throwable throwable) {
303304
exception.headers());
304305
return true;
305306
}
307+
if (Response.Status.Family.CLIENT_ERROR.equals(Response.Status.Family.familyOf(exception.statusCode()))
308+
&& exception.getMessage().contains("\"assignee\"")) {
309+
// we probably were trying to assign to an inactive or incorrectly configured
310+
// user and the request failed,
311+
// no point in retrying that ...
312+
return false;
313+
}
306314
}
307315
return false;
308316
}

src/main/java/org/hibernate/infra/replicate/jira/service/jira/handler/JiraIssueUpsertEventHandler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,19 @@ protected void doRun() {
4242
context.createNextPlaceholderBatch(destinationKey);
4343

4444
try {
45-
context.destinationJiraClient().update(destinationKey, issueToCreate(sourceIssue));
45+
JiraIssue issue = issueToCreate(sourceIssue);
46+
try {
47+
context.destinationJiraClient().update(destinationKey, issue);
48+
} catch (JiraRestException e) {
49+
if (e.getMessage().contains("\"assignee\"")) {
50+
failureCollector.warning(
51+
"Unable to update issue %s with assignee, will try to update all but assignee field."
52+
.formatted(sourceIssue.key),
53+
e);
54+
issue.fields.assignee = null;
55+
context.destinationJiraClient().update(destinationKey, issue);
56+
}
57+
}
4658
// remote "aka web" links cannot be added in the same request and are also not
4759
// returned as part of the issue API.
4860
// We "upsert" the remote link pointing to the "original/source" issue that

0 commit comments

Comments
 (0)