Skip to content

Commit

Permalink
Workflow idempotency changes
Browse files Browse the repository at this point in the history
  • Loading branch information
manan164 committed Nov 20, 2023
1 parent 2a8adad commit 129896c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2020 Netflix, Inc.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.netflix.conductor.common.metadata.workflow;

public enum IdempotencyStrategy {
FAIL,
RETURN_EXISTING
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ public class StartWorkflowRequest {
@ProtoField(id = 9)
private String createdBy;

private String idempotencyKey;

private IdempotencyStrategy idempotencyStrategy;

public String getIdempotencyKey() {
return idempotencyKey;
}

public void setIdempotencyKey(String idempotencyKey) {
this.idempotencyKey = idempotencyKey;
}

public IdempotencyStrategy getIdempotencyStrategy() {
return idempotencyStrategy;
}

public void setIdempotencyStrategy(IdempotencyStrategy idempotencyStrategy) {
this.idempotencyStrategy = idempotencyStrategy;
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public boolean isSuccessful() {
@ProtoField(id = 25)
private List<Workflow> history = new LinkedList<>();

@ProtoField(id = 26)
private String idempotencyKey;

public String getIdempotencyKey() {
return idempotencyKey;
}

public void setIdempotencyKey(String idempotencyKey) {
this.idempotencyKey = idempotencyKey;
}

public List<Workflow> getHistory() {
return history;
}
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/com/netflix/conductor/model/WorkflowModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public boolean isSuccessful() {
private String failedTaskId;

private Status previousStatus;
private String idempotencyKey;

private List<WorkflowModel> history = new LinkedList<>();

Expand Down Expand Up @@ -449,6 +450,14 @@ public TaskModel getTaskByRefName(String refName) {
return found.getLast();
}

public String getIdempotencyKey() {
return idempotencyKey;
}

public void setIdempotencyKey(String idempotencyKey) {
this.idempotencyKey = idempotencyKey;
}

public void externalizeInput(String path) {
this.inputPayload = this.input;
this.input = new HashMap<>();
Expand Down Expand Up @@ -511,6 +520,7 @@ && getStatus() == that.getStatus()
&& Objects.equals(getCreateTime(), that.getCreateTime())
&& Objects.equals(getUpdatedTime(), that.getUpdatedTime())
&& Objects.equals(getCreatedBy(), that.getCreatedBy())
&& getIdempotencyKey() == that.getIdempotencyKey()
&& Objects.equals(getUpdatedBy(), that.getUpdatedBy());
}

Expand Down Expand Up @@ -538,6 +548,7 @@ public int hashCode() {
getVariables(),
getLastRetriedTime(),
getOwnerApp(),
getIdempotencyKey(),
getCreateTime(),
getUpdatedTime(),
getCreatedBy(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@ public WorkflowPb.Workflow toProto(Workflow from) {
for (Workflow elem : from.getHistory()) {
to.addHistory( toProto(elem) );
}
if (from.getIdempotencyKey() != null) {
to.setIdempotencyKey( from.getIdempotencyKey() );
}
return to.build();
}

Expand Down Expand Up @@ -1122,6 +1125,7 @@ public Workflow fromProto(WorkflowPb.Workflow from) {
to.setVariables(variablesMap);
to.setLastRetriedTime( from.getLastRetriedTime() );
to.setHistory( from.getHistoryList().stream().map(this::fromProto).collect(Collectors.toCollection(ArrayList::new)) );
to.setIdempotencyKey( from.getIdempotencyKey() );
return to;
}

Expand Down
1 change: 1 addition & 0 deletions grpc/src/main/proto/model/workflow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ message Workflow {
map<string, google.protobuf.Value> variables = 23;
int64 last_retried_time = 24;
repeated Workflow history = 25;
string idempotency_key = 26;
}

0 comments on commit 129896c

Please sign in to comment.