Skip to content

Commit 430d486

Browse files
Add new column for trigger source in flow_run table (#1096)
1 parent 16283f7 commit 430d486

File tree

7 files changed

+71
-3
lines changed

7 files changed

+71
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FlowRunTriggerSource } from '@openops/shared';
2+
import { MigrationInterface, QueryRunner } from 'typeorm';
3+
4+
export class AddTriggerSourceToFlowRun1754489349007
5+
implements MigrationInterface
6+
{
7+
public async up(queryRunner: QueryRunner): Promise<void> {
8+
await queryRunner.query(`
9+
ALTER TABLE flow_run
10+
ADD COLUMN IF NOT EXISTS "triggerSource" varchar;
11+
12+
UPDATE flow_run
13+
SET "triggerSource" = CASE
14+
WHEN environment = 'TESTING' THEN '${FlowRunTriggerSource.TEST_RUN}'
15+
ELSE '${FlowRunTriggerSource.TRIGGERED}'
16+
END
17+
WHERE "triggerSource" IS NULL;
18+
19+
ALTER TABLE flow_run
20+
ALTER COLUMN "triggerSource" SET NOT NULL;
21+
`);
22+
}
23+
24+
public async down(queryRunner: QueryRunner): Promise<void> {
25+
await queryRunner.query(`
26+
ALTER TABLE flow_run DROP COLUMN IF EXISTS "triggerSource";
27+
`);
28+
}
29+
}

packages/server/api/src/app/database/postgres-connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { AddInputToTestOutputTable1750933522145 } from './migrations/17509335221
2929
import { AddInputToTriggerEventTable1751282188913 } from './migrations/1751282188913-AddInputToTriggerEventTable';
3030
import { AddSuccessToFlowStepTestOutputTable1752487641303 } from './migrations/1752487641303-AddSuccessToFlowStepTestOutputTable';
3131
import { UpdateUmbrellaRecommendationTypesAcrossFlowVersions1752758891771 } from './migrations/1752758891771-UpdateUmbrellaRecommendationTypesAcrossFlowVersions';
32+
import { AddTriggerSourceToFlowRun1754489349007 } from './migrations/1754489349007-AddTriggerSourceToFlowRun';
3233

3334
const getSslConfig = (): boolean | TlsOptions => {
3435
const useSsl = system.get(AppSystemProp.POSTGRES_USE_SSL);
@@ -66,6 +67,7 @@ const getMigrations = (): (new () => MigrationInterface)[] => {
6667
AddInputToTriggerEventTable1751282188913,
6768
AddSuccessToFlowStepTestOutputTable1752487641303,
6869
UpdateUmbrellaRecommendationTypesAcrossFlowVersions1752758891771,
70+
AddTriggerSourceToFlowRun1754489349007,
6971
];
7072
};
7173

packages/server/api/src/app/flows/flow-run/flow-run-entity.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { File, Flow, FlowRun, Project } from '@openops/shared';
1+
import {
2+
File,
3+
Flow,
4+
FlowRun,
5+
FlowRunTriggerSource,
6+
Project,
7+
} from '@openops/shared';
28
import { EntitySchema } from 'typeorm';
39
import {
410
ARRAY_COLUMN_TYPE,
@@ -36,6 +42,10 @@ export const FlowRunEntity = new EntitySchema<FlowRunSchema>({
3642
status: {
3743
type: String,
3844
},
45+
triggerSource: {
46+
type: String,
47+
enum: Object.values(FlowRunTriggerSource),
48+
},
3949
terminationReason: {
4050
type: String,
4151
nullable: true,

packages/server/api/src/app/flows/flow-run/flow-run-service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
FlowRun,
1414
FlowRunId,
1515
FlowRunStatus,
16+
FlowRunTriggerSource,
1617
FlowVersionId,
1718
isEmpty,
1819
isNil,
@@ -47,8 +48,15 @@ export const flowRunRepo = repoFactory<FlowRun>(FlowRunEntity);
4748
const getFlowRunOrCreate = async (
4849
params: GetOrCreateParams,
4950
): Promise<Partial<FlowRun>> => {
50-
const { id, projectId, flowId, flowVersionId, flowDisplayName, environment } =
51-
params;
51+
const {
52+
id,
53+
projectId,
54+
flowId,
55+
flowVersionId,
56+
flowDisplayName,
57+
environment,
58+
triggerSource,
59+
} = params;
5260

5361
if (id) {
5462
return flowRunService.getOneOrThrow({
@@ -65,6 +73,7 @@ const getFlowRunOrCreate = async (
6573
environment,
6674
flowDisplayName,
6775
startTime: new Date().toISOString(),
76+
triggerSource,
6877
};
6978
};
7079

@@ -254,6 +263,7 @@ export const flowRunService = {
254263
progressUpdateType,
255264
executionType,
256265
environment: RunEnvironment.PRODUCTION,
266+
triggerSource: flowRunToResume.triggerSource,
257267
});
258268
},
259269
async updateStatus({
@@ -302,6 +312,7 @@ export const flowRunService = {
302312
synchronousHandlerId,
303313
progressUpdateType,
304314
executionCorrelationId,
315+
triggerSource,
305316
}: StartParams): Promise<FlowRun> {
306317
const flowVersion = await flowVersionService.getOneOrThrow(flowVersionId);
307318

@@ -317,6 +328,7 @@ export const flowRunService = {
317328
flowVersionId: flowVersion.id,
318329
environment,
319330
flowDisplayName: flowVersion.displayName,
331+
triggerSource,
320332
});
321333

322334
flowRun.status = FlowRunStatus.SCHEDULED;
@@ -364,6 +376,7 @@ export const flowRunService = {
364376
synchronousHandlerId: webhookResponseWatcher.getServerId(),
365377
executionCorrelationId: nanoid(),
366378
progressUpdateType: ProgressUpdateType.TEST_FLOW,
379+
triggerSource: FlowRunTriggerSource.TEST_RUN,
367380
});
368381
},
369382

@@ -492,6 +505,7 @@ type GetOrCreateParams = {
492505
flowVersionId: FlowVersionId;
493506
flowDisplayName: string;
494507
environment: RunEnvironment;
508+
triggerSource: FlowRunTriggerSource;
495509
};
496510

497511
type ListParams = {
@@ -520,6 +534,7 @@ type StartParams = {
520534
executionCorrelationId: string;
521535
progressUpdateType: ProgressUpdateType;
522536
executionType: ExecutionType;
537+
triggerSource: FlowRunTriggerSource;
523538
};
524539

525540
type TestParams = {

packages/server/api/src/app/workers/worker-controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '@openops/server-shared';
1616
import {
1717
ExecutionType,
18+
FlowRunTriggerSource,
1819
openOpsId,
1920
PrincipalType,
2021
ProgressUpdateType,
@@ -162,6 +163,7 @@ export const flowWorkerController: FastifyPluginAsyncTypebox = async (app) => {
162163
executionCorrelationId,
163164
executionType: ExecutionType.BEGIN,
164165
progressUpdateType,
166+
triggerSource: FlowRunTriggerSource.TRIGGERED,
165167
}),
166168
);
167169
return Promise.all(createFlowRuns);
@@ -194,6 +196,7 @@ export const flowWorkerController: FastifyPluginAsyncTypebox = async (app) => {
194196
executionCorrelationId: data.executionCorrelationId,
195197
environment: RunEnvironment.PRODUCTION,
196198
progressUpdateType: data.progressUpdateType ?? ProgressUpdateType.NONE,
199+
triggerSource: FlowRunTriggerSource.TRIGGERED,
197200
});
198201
},
199202
);

packages/server/api/test/helpers/mocks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
FlowImportTemplate,
99
FlowRun,
1010
FlowRunStatus,
11+
FlowRunTriggerSource,
1112
FlowStatus,
1213
FlowVersion,
1314
FlowVersionState,
@@ -202,6 +203,7 @@ export const createMockFlowRun = (flowRun?: Partial<FlowRun>): FlowRun => {
202203
finishTime: flowRun?.finishTime ?? faker.date.recent().toISOString(),
203204
environment:
204205
flowRun?.environment ?? faker.helpers.enumValue(RunEnvironment),
206+
triggerSource: flowRun?.triggerSource ?? FlowRunTriggerSource.TEST_RUN,
205207
};
206208
};
207209

packages/shared/src/lib/flow-run/flow-run.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export type FlowRetryPayload = {
2020
strategy: FlowRetryStrategy;
2121
};
2222

23+
export enum FlowRunTriggerSource {
24+
TRIGGERED = 'TRIGGERED',
25+
TEST_RUN = 'TEST_RUN',
26+
MANUAL_RUN = 'MANUAL_RUN',
27+
}
28+
2329
export const FlowRun = Type.Object({
2430
...BaseModelSchema,
2531
projectId: Type.String(),
@@ -32,6 +38,7 @@ export const FlowRun = Type.Object({
3238
logsFileId: Nullable(Type.String()),
3339
tasks: Type.Optional(Type.Number()),
3440
status: Type.Enum(FlowRunStatus),
41+
triggerSource: Type.Enum(FlowRunTriggerSource),
3542
duration: Type.Optional(Type.Number()),
3643
startTime: Type.String(),
3744
finishTime: Type.Optional(Type.String()),

0 commit comments

Comments
 (0)