Add cron trigger table (#14110)
This Pr begins the extensibility journey - adds a `core.cronTrigger` table - add a oneToMany relation between core.serverlessFunction and `core.cronTrigger` (one serverlessFunction can be triggered by multiple cronTriggers) - add a job to trigger a serverless function - adds a cron to trigger serverlessFunction (via the trigger job) based on the core.cronTrigger.setting.pattern - adds a command to register the cron - add the command in `cron-register-all.command.ts`
This commit is contained in:
@@ -14,6 +14,7 @@ import { WorkflowCleanWorkflowRunsCommand } from 'src/modules/workflow/workflow-
|
||||
import { WorkflowHandleStaledRunsCronCommand } from 'src/modules/workflow/workflow-runner/workflow-run-queue/cron/command/workflow-handle-staled-runs.cron.command';
|
||||
import { WorkflowRunEnqueueCronCommand } from 'src/modules/workflow/workflow-runner/workflow-run-queue/cron/command/workflow-run-enqueue.cron.command';
|
||||
import { WorkflowCronTriggerCronCommand } from 'src/modules/workflow/workflow-trigger/automated-trigger/crons/commands/workflow-cron-trigger.cron.command';
|
||||
import { CronTriggerCronCommand } from 'src/engine/metadata-modules/trigger/crons/commands/cron-trigger.cron.command';
|
||||
|
||||
@Command({
|
||||
name: 'cron:register:all',
|
||||
@@ -35,6 +36,7 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
private readonly workflowRunEnqueueCronCommand: WorkflowRunEnqueueCronCommand,
|
||||
private readonly workflowHandleStaledRunsCronCommand: WorkflowHandleStaledRunsCronCommand,
|
||||
private readonly workflowCleanWorkflowRunsCronCommand: WorkflowCleanWorkflowRunsCommand,
|
||||
private readonly cronTriggerCronCommand: CronTriggerCronCommand,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -91,6 +93,10 @@ export class CronRegisterAllCommand extends CommandRunner {
|
||||
name: 'WorkflowCleanWorkflowRuns',
|
||||
command: this.workflowCleanWorkflowRunsCronCommand,
|
||||
},
|
||||
{
|
||||
name: 'CronTrigger',
|
||||
command: this.cronTriggerCronCommand,
|
||||
},
|
||||
];
|
||||
|
||||
let successCount = 0;
|
||||
|
||||
@@ -21,6 +21,7 @@ import { CalendarEventImportManagerModule } from 'src/modules/calendar/calendar-
|
||||
import { MessagingImportManagerModule } from 'src/modules/messaging/message-import-manager/messaging-import-manager.module';
|
||||
import { WorkflowRunQueueModule } from 'src/modules/workflow/workflow-runner/workflow-run-queue/workflow-run-queue.module';
|
||||
import { AutomatedTriggerModule } from 'src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module';
|
||||
import { TriggerModule } from 'src/engine/metadata-modules/trigger/trigger.module';
|
||||
|
||||
import { DataSeedWorkspaceCommand } from './data-seed-dev-workspace.command';
|
||||
|
||||
@@ -45,6 +46,7 @@ import { DataSeedWorkspaceCommand } from './data-seed-dev-workspace.command';
|
||||
WorkspaceCacheStorageModule,
|
||||
ApiKeyModule,
|
||||
FeatureFlagModule,
|
||||
TriggerModule,
|
||||
],
|
||||
providers: [
|
||||
DataSeedWorkspaceCommand,
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import { type MigrationInterface, type QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddCronTriggerEntity1756373902817 implements MigrationInterface {
|
||||
name = 'AddCronTriggerEntity1756373902817';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "core"."cronTrigger" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "settings" jsonb NOT NULL, "workspaceId" uuid NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "serverlessFunctionId" uuid, CONSTRAINT "PK_153e054abdb2663942d4661e3bb" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_CRON_TRIGGER_WORKSPACE_ID" ON "core"."cronTrigger" ("workspaceId") `,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."cronTrigger" ADD CONSTRAINT "FK_f70831ec336e0cb42d6a33b80ba" FOREIGN KEY ("serverlessFunctionId") REFERENCES "core"."serverlessFunction"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "core"."cronTrigger" DROP CONSTRAINT "FK_f70831ec336e0cb42d6a33b80ba"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "core"."IDX_CRON_TRIGGER_WORKSPACE_ID"`,
|
||||
);
|
||||
await queryRunner.query(`DROP TABLE "core"."cronTrigger"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user