feat: Add published_at column to flows and adjust update flow status
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
import { Knex } from 'knex';
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
return knex.schema.table('flows', (table) => {
|
||||||
|
table.timestamp('published_at').nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
return knex.schema.table('flows', (table) => {
|
||||||
|
table.dropColumn('published_at');
|
||||||
|
});
|
||||||
|
}
|
@@ -36,9 +36,13 @@ const updateFlowStatus = async (
|
|||||||
const interval = trigger.interval;
|
const interval = trigger.interval;
|
||||||
const repeatOptions = {
|
const repeatOptions = {
|
||||||
cron: interval || EVERY_15_MINUTES_CRON,
|
cron: interval || EVERY_15_MINUTES_CRON,
|
||||||
}
|
};
|
||||||
|
|
||||||
if (flow.active) {
|
if (flow.active) {
|
||||||
|
flow = await flow.$query().patchAndFetch({
|
||||||
|
published_at: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
|
||||||
await processorQueue.add(
|
await processorQueue.add(
|
||||||
JOB_NAME,
|
JOB_NAME,
|
||||||
{ flowId: flow.id },
|
{ flowId: flow.id },
|
||||||
@@ -49,7 +53,7 @@ const updateFlowStatus = async (
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const repeatableJobs = await processorQueue.getRepeatableJobs();
|
const repeatableJobs = await processorQueue.getRepeatableJobs();
|
||||||
const job = repeatableJobs.find(job => job.id === flow.id);
|
const job = repeatableJobs.find((job) => job.id === flow.id);
|
||||||
|
|
||||||
await processorQueue.removeRepeatableByKey(job.key);
|
await processorQueue.removeRepeatableByKey(job.key);
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ class Flow extends Base {
|
|||||||
userId!: string;
|
userId!: string;
|
||||||
active = false;
|
active = false;
|
||||||
steps?: [Step];
|
steps?: [Step];
|
||||||
|
published_at: string;
|
||||||
|
|
||||||
static tableName = 'flows';
|
static tableName = 'flows';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user