Add flow to run output (#10220)
We need the version trigger and steps to be stored in the output. We should not rely on the version itself because some run are made on draft versions. Which means versions could be edited afterwards.
This commit is contained in:
@ -11,4 +11,5 @@ export enum WorkflowRunExceptionCode {
|
||||
INVALID_OPERATION = 'INVALID_OPERATION',
|
||||
INVALID_INPUT = 'INVALID_INPUT',
|
||||
WORKFLOW_RUN_LIMIT_REACHED = 'WORKFLOW_RUN_LIMIT_REACHED',
|
||||
WORKFLOW_RUN_INVALID = 'WORKFLOW_RUN_INVALID',
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Logger, Scope } from '@nestjs/common';
|
||||
import { Scope } from '@nestjs/common';
|
||||
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
@ -23,7 +23,6 @@ export type RunWorkflowJobData = {
|
||||
|
||||
@Processor({ queueName: MessageQueue.workflowQueue, scope: Scope.REQUEST })
|
||||
export class RunWorkflowJob {
|
||||
private readonly logger = new Logger(RunWorkflowJob.name);
|
||||
constructor(
|
||||
private readonly workflowCommonWorkspaceService: WorkflowCommonWorkspaceService,
|
||||
private readonly workflowExecutorWorkspaceService: WorkflowExecutorWorkspaceService,
|
||||
@ -42,26 +41,39 @@ export class RunWorkflowJob {
|
||||
trigger: payload,
|
||||
};
|
||||
|
||||
await this.workflowRunWorkspaceService.startWorkflowRun({
|
||||
workflowRunId,
|
||||
context,
|
||||
});
|
||||
|
||||
try {
|
||||
const workflowVersion =
|
||||
await this.workflowCommonWorkspaceService.getWorkflowVersionOrFail(
|
||||
workflowVersionId,
|
||||
);
|
||||
|
||||
if (!workflowVersion.trigger || !workflowVersion.steps) {
|
||||
throw new WorkflowRunException(
|
||||
'Workflow version has no trigger or steps',
|
||||
WorkflowRunExceptionCode.WORKFLOW_RUN_INVALID,
|
||||
);
|
||||
}
|
||||
|
||||
await this.workflowRunWorkspaceService.startWorkflowRun({
|
||||
workflowRunId,
|
||||
context,
|
||||
output: {
|
||||
flow: {
|
||||
trigger: workflowVersion.trigger,
|
||||
steps: workflowVersion.steps,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await this.throttleExecution(workflowVersion.workflowId);
|
||||
|
||||
const { status } = await this.workflowExecutorWorkspaceService.execute({
|
||||
workflowRunId,
|
||||
currentStepIndex: 0,
|
||||
steps: workflowVersion.steps || [],
|
||||
steps: workflowVersion.steps ?? [],
|
||||
context,
|
||||
workflowExecutorOutput: {
|
||||
steps: {},
|
||||
workflowExecutorState: {
|
||||
stepsOutput: {},
|
||||
status: WorkflowRunStatus.RUNNING,
|
||||
},
|
||||
});
|
||||
|
||||
@ -51,9 +51,11 @@ export class WorkflowRunWorkspaceService {
|
||||
async startWorkflowRun({
|
||||
workflowRunId,
|
||||
context,
|
||||
output,
|
||||
}: {
|
||||
workflowRunId: string;
|
||||
context: Record<string, any>;
|
||||
output: Pick<WorkflowRunOutput, 'flow'>;
|
||||
}) {
|
||||
const workflowRunRepository =
|
||||
await this.twentyORMManager.getRepository<WorkflowRunWorkspaceEntity>(
|
||||
@ -82,6 +84,7 @@ export class WorkflowRunWorkspaceService {
|
||||
status: WorkflowRunStatus.RUNNING,
|
||||
startedAt: new Date().toISOString(),
|
||||
context,
|
||||
output,
|
||||
});
|
||||
}
|
||||
|
||||
@ -133,7 +136,7 @@ export class WorkflowRunWorkspaceService {
|
||||
context,
|
||||
}: {
|
||||
workflowRunId: string;
|
||||
output: WorkflowRunOutput;
|
||||
output: Pick<WorkflowRunOutput, 'error' | 'stepsOutput'>;
|
||||
context: Record<string, any>;
|
||||
}) {
|
||||
const workflowRunRepository =
|
||||
@ -153,7 +156,13 @@ export class WorkflowRunWorkspaceService {
|
||||
}
|
||||
|
||||
return workflowRunRepository.update(workflowRunId, {
|
||||
output,
|
||||
output: {
|
||||
flow: workflowRunToUpdate.output?.flow ?? {
|
||||
trigger: undefined,
|
||||
steps: [],
|
||||
},
|
||||
...output,
|
||||
},
|
||||
context,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user