Skip to content

Commit

Permalink
Reorder methods for logical relationships
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Oct 2, 2024
1 parent f6c194e commit c821b4a
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,14 @@ public <T> void canDeleteWorkflowStateDoc(
}

/**
* Updates a complete document in the workflow state index
* Updates a partial document in the workflow state index
* @param documentId the document ID
* @param updatedDocument a complete document to update the global state index with
* @param updatedFields the fields to update the global state index with
* @param listener action listener
*/
public void updateFlowFrameworkSystemIndexDoc(
String documentId,
ToXContentObject updatedDocument,
Map<String, Object> updatedFields,
ActionListener<UpdateResponse> listener
) {
if (!doesIndexExist(WORKFLOW_STATE_INDEX)) {
Expand All @@ -595,11 +595,11 @@ public void updateFlowFrameworkSystemIndexDoc(
} else {
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
UpdateRequest updateRequest = new UpdateRequest(WORKFLOW_STATE_INDEX, documentId);
XContentBuilder builder = XContentFactory.jsonBuilder();
updatedDocument.toXContent(builder, null);
updateRequest.doc(builder);
Map<String, Object> updatedContent = new HashMap<>(updatedFields);
updateRequest.doc(updatedContent);
updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
updateRequest.retryOnConflict(5);
// TODO: decide what condition can be considered as an update conflict and add retry strategy
client.update(updateRequest, ActionListener.runBefore(listener, context::restore));
} catch (Exception e) {
String errorMessage = "Failed to update " + WORKFLOW_STATE_INDEX + " entry : " + documentId;
Expand All @@ -610,14 +610,14 @@ public void updateFlowFrameworkSystemIndexDoc(
}

/**
* Updates a partial document in the workflow state index
* Updates a complete document in the workflow state index
* @param documentId the document ID
* @param updatedFields the fields to update the global state index with
* @param updatedDocument a complete document to update the global state index with
* @param listener action listener
*/
public void updateFlowFrameworkSystemIndexDoc(
String documentId,
Map<String, Object> updatedFields,
ToXContentObject updatedDocument,
ActionListener<UpdateResponse> listener
) {
if (!doesIndexExist(WORKFLOW_STATE_INDEX)) {
Expand All @@ -627,11 +627,11 @@ public void updateFlowFrameworkSystemIndexDoc(
} else {
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
UpdateRequest updateRequest = new UpdateRequest(WORKFLOW_STATE_INDEX, documentId);
Map<String, Object> updatedContent = new HashMap<>(updatedFields);
updateRequest.doc(updatedContent);
XContentBuilder builder = XContentFactory.jsonBuilder();
updatedDocument.toXContent(builder, null);
updateRequest.doc(builder);
updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
updateRequest.retryOnConflict(5);
// TODO: decide what condition can be considered as an update conflict and add retry strategy
client.update(updateRequest, ActionListener.runBefore(listener, context::restore));
} catch (Exception e) {
String errorMessage = "Failed to update " + WORKFLOW_STATE_INDEX + " entry : " + documentId;
Expand Down

0 comments on commit c821b4a

Please sign in to comment.