From ca7ec6a0cb5f5ccffb0b5a902d403972956bf7cf Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Tue, 6 Feb 2024 20:30:27 +0100 Subject: [PATCH] Checkpoint Signed-off-by: bnechyporenko --- .../tasks/NunjucksWorkflowRunner.ts | 5 ++- plugins/scaffolder-node/src/tasks/types.ts | 36 +++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts index 407c623793..e9fc334ea0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts @@ -357,7 +357,10 @@ export class NunjucksWorkflowRunner implements WorkflowRunner { try { let prevValue: U | undefined; if (prevTaskState) { - prevValue = prevTaskState.state[key] as unknown as U; + const prevState = prevTaskState.state[key]; + if (prevState.status === 'success') { + prevValue = prevState.value as U; + } } const value = prevValue ? prevValue : await fn(); diff --git a/plugins/scaffolder-node/src/tasks/types.ts b/plugins/scaffolder-node/src/tasks/types.ts index c6654ea642..62933ad666 100644 --- a/plugins/scaffolder-node/src/tasks/types.ts +++ b/plugins/scaffolder-node/src/tasks/types.ts @@ -26,6 +26,24 @@ export type TaskSecrets = Record & { backstageToken?: string; }; +/** + * The record passed to {@link TaskBroker.updateCheckpoint?} + * Parameters to store the result of the executed checkpoint + * + * @public + */ +export type CheckpointRecord = + | { + key: string; + status: 'success'; + value: JsonObject; + } + | { + key: string; + status: 'failed'; + reason: string; + }; + /** * TaskState * @@ -115,24 +133,6 @@ export type TaskBrokerDispatchOptions = { createdBy?: string; }; -/** - * The record passed to {@link TaskBroker.updateCheckpoint?} - * Parameters to store the result of the executed checkpoint - * - * @public - */ -export type CheckpointRecord = - | { - key: string; - status: 'success'; - value: JsonObject; - } - | { - key: string; - status: 'failed'; - reason: string; - }; - /** * Task *