Perform batch update on workflow runs (#11680)

Command times out on workflow versions with too many runs. Performing
batch update instead
This commit is contained in:
Thomas Trompette
2025-04-22 16:07:29 +02:00
committed by GitHub
parent 5250d5c8d6
commit 0b7024c94a

View File

@ -11,6 +11,7 @@ import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager'; import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity'; import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity'; import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
import { WorkflowTrigger } from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
@Command({ @Command({
name: 'upgrade:0-52:backfill-workflow-next-step-ids', name: 'upgrade:0-52:backfill-workflow-next-step-ids',
@ -76,6 +77,8 @@ export class BackfillWorkflowNextStepIdsCommand extends ActiveOrSuspendedWorkspa
}, },
}); });
const workflowRunsToUpdate: WorkflowRunWorkspaceEntity[] = [];
for (const workflowRun of workflowRuns) { for (const workflowRun of workflowRuns) {
const flow = workflowRun.output?.flow; const flow = workflowRun.output?.flow;
@ -92,18 +95,22 @@ export class BackfillWorkflowNextStepIdsCommand extends ActiveOrSuspendedWorkspa
}; };
}); });
await workflowRunRepository.save({ const updatedWorkflowRun: WorkflowRunWorkspaceEntity = {
...workflowRun, ...workflowRun,
output: { output: {
...workflowRun.output, ...workflowRun.output,
flow: { flow: {
...workflowRun.output?.flow, trigger: workflowRun.output?.flow?.trigger as WorkflowTrigger,
steps: updatedFlow, steps: updatedFlow,
}, },
}, },
}); };
workflowRunsToUpdate.push(updatedWorkflowRun);
} }
await workflowRunRepository.save(workflowRunsToUpdate);
await workflowVersionRepository.save({ await workflowVersionRepository.save({
...workflowVersion, ...workflowVersion,
steps: updatedSteps, steps: updatedSteps,