Skip to content

Commit

Permalink
fix: update flow.active when remote calls succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
barinali committed Jun 11, 2023
1 parent e548dd4 commit 1449fb0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/backend/src/graphql/mutations/update-flow-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ const updateFlowStatus = async (
})
.throwIfNotFound();

if (flow.active === params.input.active) {
const newActiveValue = params.input.active;

if (flow.active === newActiveValue) {
return flow;
}

flow = await flow.$query().withGraphFetched('steps').patchAndFetch({
active: params.input.active,
});

const triggerStep = await flow.getTriggerStep();
const trigger = await triggerStep.getTriggerCommand();
const interval = trigger.getInterval?.(triggerStep.parameters);
Expand All @@ -49,13 +47,13 @@ const updateFlowStatus = async (
testRun: false,
});

if (flow.active && trigger.registerHook) {
if (newActiveValue && trigger.registerHook) {
await trigger.registerHook($);
} else if (!flow.active && trigger.unregisterHook) {
} else if (!newActiveValue && trigger.unregisterHook) {
await trigger.unregisterHook($);
}
} else {
if (flow.active) {
if (newActiveValue) {
flow = await flow.$query().patchAndFetch({
published_at: new Date().toISOString(),
});
Expand All @@ -80,6 +78,10 @@ const updateFlowStatus = async (
}
}

flow = await flow.$query().withGraphFetched('steps').patchAndFetch({
active: newActiveValue,
});

return flow;
};

Expand Down

0 comments on commit 1449fb0

Please sign in to comment.