From 003a3add8f8c2203dfe74f1e19e564584ab144a3 Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Tue, 26 Dec 2023 08:32:56 -0700 Subject: [PATCH] handle undefined condition for trigger edges --- packages/ws-worker/src/util/convert-attempt.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/ws-worker/src/util/convert-attempt.ts b/packages/ws-worker/src/util/convert-attempt.ts index db7a60bb4..d2bbd14f7 100644 --- a/packages/ws-worker/src/util/convert-attempt.ts +++ b/packages/ws-worker/src/util/convert-attempt.ts @@ -25,6 +25,14 @@ const mapEdgeCondition = (edge: Edge) => { return condition; }; +const mapTriggerEdgeCondition = (edge: Edge) => { + const { condition } = edge; + // This handles cron triggers with undefined conditions and the 'always' string. + if (condition === undefined || condition === 'always') return true; + // Otherwise, we will return the condition and assume it's a valid JS expression. + return condition; +}; + export default ( attempt: Attempt ): { plan: ExecutionPlan; options: AttemptOptions } => { @@ -63,8 +71,7 @@ export default ( nodes[id].next = connectedEdges.reduce((obj, edge) => { if (edge.enabled !== false) { // @ts-ignore - obj[edge.target_job_id] = - edge.condition == 'always' ? true : edge.condition; + obj[edge.target_job_id] = mapTriggerEdgeCondition(edge); } return obj; }, {});