Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update flow.active when remote calls succeed #1139

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading