Skip to content

Commit

Permalink
Merge pull request #136 from sriharimalagi/feature/keepLastN
Browse files Browse the repository at this point in the history
Feature/keepLastN
  • Loading branch information
v1r3n authored May 26, 2024
2 parents b7946d0 + 1a1b459 commit 3e85e96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import javax.script.ScriptException;

Expand Down Expand Up @@ -111,6 +112,17 @@ public boolean execute(
}
doWhileTaskModel.addOutput(String.valueOf(doWhileTaskModel.getIteration()), output);

Optional<Integer> keepLastN =
Optional.ofNullable(doWhileTaskModel.getWorkflowTask().getInputParameters())
.map(parameters -> parameters.get("keepLastN"))
.map(value -> (Integer) value);
if (keepLastN.isPresent() && doWhileTaskModel.getIteration() > keepLastN.get()) {
Integer iteration = doWhileTaskModel.getIteration();
IntStream.range(0, iteration - keepLastN.get() - 1)
.mapToObj(Integer::toString)
.forEach(doWhileTaskModel::removeOutput);
}

if (hasFailures) {
LOGGER.debug(
"Task {} failed in {} iteration",
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/com/netflix/conductor/model/TaskModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,10 @@ public void addOutput(String key, Object value) {
this.outputData.put(key, value);
}

public void removeOutput(String key) {
this.outputData.remove(key);
}

public void addOutput(Map<String, Object> outputData) {
if (outputData != null) {
this.outputData.putAll(outputData);
Expand Down

0 comments on commit 3e85e96

Please sign in to comment.