Skip to content

Commit

Permalink
feat(core): add an originalId that will be the same in case of replay
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Mar 2, 2023
1 parent cf0e646 commit 049855e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
23 changes: 23 additions & 0 deletions core/src/main/java/io/kestra/core/models/executions/Execution.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,33 @@ public class Execution implements DeletedInterface {

String parentId;

String originalId;

@With
ExecutionTrigger trigger;

@NotNull
@Builder.Default
boolean deleted = false;

public static class ExecutionBuilder {
void prebuild() {
this.originalId = this.id;
}
}

public static ExecutionBuilder builder() {
return new CustomExecutionBuilder();
}

private static class CustomExecutionBuilder extends ExecutionBuilder {
@Override
public Execution build() {
this.prebuild();
return super.build();
}
}

public Execution withState(State.Type state) {
return new Execution(
this.id,
Expand All @@ -76,6 +96,7 @@ public Execution withState(State.Type state) {
this.variables,
this.state.withState(state),
this.parentId,
this.originalId,
this.trigger,
this.deleted
);
Expand Down Expand Up @@ -104,6 +125,7 @@ public Execution withTaskRun(TaskRun taskRun) throws InternalException {
this.variables,
this.state,
this.parentId,
this.originalId,
this.trigger,
this.deleted
);
Expand All @@ -120,6 +142,7 @@ public Execution childExecution(String childExecutionId, List<TaskRun> taskRunLi
this.variables,
state,
childExecutionId != null ? this.getId() : null,
this.originalId,
this.trigger,
this.deleted
);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/io/kestra/core/runners/RunContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ protected Map<String, Object> variables(Flow flow, Task task, Execution executio
builder
.put("execution", ImmutableMap.of(
"id", execution.getId(),
"originalId", execution.getOriginalId(),
"startDate", execution.getState().getStartDate()
));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.core.models.executions;

import io.kestra.core.utils.IdUtils;
import org.junit.jupiter.api.Test;
import io.kestra.core.models.flows.State;

Expand Down Expand Up @@ -124,4 +125,27 @@ void hasTaskRunJoinableAfterRestart() {
.build()
), is(true));
}

@Test
void originalId() {
Execution execution = Execution.builder()
.id(IdUtils.create())
.state(new State())
.build();
assertThat(execution.getOriginalId(), is(execution.getId()));

Execution restart1 = execution.childExecution(
IdUtils.create(),
execution.getTaskRunList(),
execution.withState(State.Type.RESTARTED).getState()
);
assertThat(restart1.getOriginalId(), is(execution.getId()));

Execution restart2 = restart1.childExecution(
IdUtils.create(),
restart1.getTaskRunList(),
restart1.withState(State.Type.PAUSED).getState()
);
assertThat(restart2.getOriginalId(), is(execution.getId()));
}
}
12 changes: 12 additions & 0 deletions ui/src/components/executions/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@
});
}
if (this.execution.originalId !== this.execution.id) {
ret.push({
key: this.$t("original execution"),
value: this.execution.originalId,
link: {
flowId: this.execution.flowId,
id: this.execution.originalId,
namespace: this.execution.namespace
}
});
}
return ret;
},
inputs() {
Expand Down
2 changes: 2 additions & 0 deletions ui/src/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"key": "Key",
"value": "Value",
"parent execution": "Parent execution",
"original execution": "Original execution",
"automatic refresh": "Automatic refresh",
"toggle periodic refresh each 10 seconds": "Toggle periodic refresh each 10 seconds",
"trigger refresh": "Trigger refresh",
Expand Down Expand Up @@ -527,6 +528,7 @@
"key": "Clé",
"value": "Valeur",
"parent execution": "Execution parente",
"original execution": "Execution d'origine",
"automatic refresh": "rafraîchissement automatique",
"toggle periodic refresh each 10 seconds": "Activer le rafraîchissement toutes les 10 secondes",
"trigger refresh": "Déclencher le rafraîchissement",
Expand Down

0 comments on commit 049855e

Please sign in to comment.