feat: Implement auto-run interval for triggers of completed flows

This commit is contained in:
Faruk AYDIN
2022-03-23 17:32:13 +03:00
committed by Ömer Faruk Aydın
parent 3715291df7
commit 22e1fe5c44
13 changed files with 134 additions and 37 deletions

View File

@@ -1,4 +1,5 @@
import Context from '../../types/express/context';
import processorQueue from '../../queues/processor';
type Params = {
input: {
@@ -7,6 +8,11 @@ type Params = {
};
};
const JOB_NAME = 'processorJob';
const REPEAT_OPTIONS = {
every: 60000, // 1 minute
};
const updateFlowStatus = async (
_parent: unknown,
params: Params,
@@ -23,10 +29,23 @@ const updateFlowStatus = async (
return flow;
}
flow = await flow.$query().patchAndFetch({
flow = await flow.$query().withGraphFetched('steps').patchAndFetch({
active: params.input.active,
});
if (flow.active) {
await processorQueue.add(
JOB_NAME,
{ flowId: flow.id },
{
repeat: REPEAT_OPTIONS,
jobId: flow.id,
}
);
} else {
await processorQueue.removeRepeatable(JOB_NAME, REPEAT_OPTIONS, flow.id);
}
return flow;
};