Add output to workflow run (#7276)
Example of output stored for following workflow: <img width="244" alt="Capture d’écran 2024-09-27 à 11 18 06" src="https://github.com/user-attachments/assets/722bfa96-2dd1-41f7-ab87-d39584ac9efc"> Output: ``` {"steps": [ {"type": "CODE", "result": {"email": "test@twenty.com"}}, {"type": "SEND_EMAIL", "result": {"success": true}} ]} ```
This commit is contained in:
@ -3,8 +3,8 @@ import { Scope } from '@nestjs/common';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
|
||||
import { WorkflowRunStatus } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
|
||||
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
|
||||
import { WorkflowExecutorWorkspaceService } from 'src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service';
|
||||
import { WorkflowRunWorkspaceService } from 'src/modules/workflow/workflow-runner/workspace-services/workflow-run.workspace-service';
|
||||
|
||||
@ -36,24 +36,23 @@ export class RunWorkflowJob {
|
||||
workflowVersionId,
|
||||
);
|
||||
|
||||
try {
|
||||
const { steps, status } =
|
||||
await this.workflowExecutorWorkspaceService.execute({
|
||||
currentStepIndex: 0,
|
||||
steps: workflowVersion.steps || [],
|
||||
payload,
|
||||
output: {
|
||||
steps: [],
|
||||
status: WorkflowRunStatus.RUNNING,
|
||||
},
|
||||
});
|
||||
|
||||
await this.workflowRunWorkspaceService.endWorkflowRun(
|
||||
workflowRunId,
|
||||
WorkflowRunStatus.COMPLETED,
|
||||
);
|
||||
} catch (error) {
|
||||
await this.workflowRunWorkspaceService.endWorkflowRun(
|
||||
workflowRunId,
|
||||
WorkflowRunStatus.FAILED,
|
||||
);
|
||||
|
||||
throw error;
|
||||
}
|
||||
await this.workflowRunWorkspaceService.endWorkflowRun(
|
||||
workflowRunId,
|
||||
status,
|
||||
{
|
||||
steps,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,11 +2,12 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { ActorMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
|
||||
import {
|
||||
WorkflowRunOutput,
|
||||
WorkflowRunStatus,
|
||||
WorkflowRunWorkspaceEntity,
|
||||
} from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
|
||||
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
|
||||
import {
|
||||
WorkflowRunException,
|
||||
WorkflowRunExceptionCode,
|
||||
@ -70,7 +71,11 @@ export class WorkflowRunWorkspaceService {
|
||||
});
|
||||
}
|
||||
|
||||
async endWorkflowRun(workflowRunId: string, status: WorkflowRunStatus) {
|
||||
async endWorkflowRun(
|
||||
workflowRunId: string,
|
||||
status: WorkflowRunStatus,
|
||||
output: WorkflowRunOutput,
|
||||
) {
|
||||
const workflowRunRepository =
|
||||
await this.twentyORMManager.getRepository<WorkflowRunWorkspaceEntity>(
|
||||
'workflowRun',
|
||||
@ -96,6 +101,7 @@ export class WorkflowRunWorkspaceService {
|
||||
|
||||
return workflowRunRepository.update(workflowRunToUpdate.id, {
|
||||
status,
|
||||
output,
|
||||
endedAt: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user