Skip to content

Commit

Permalink
fix(core): Do not emit workflow-post-execute event for waiting exec…
Browse files Browse the repository at this point in the history
…utions (#13065)
  • Loading branch information
netroy authored Feb 6, 2025
1 parent a37c8e8 commit 1593b6c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 30 deletions.
16 changes: 0 additions & 16 deletions packages/cli/src/events/__tests__/telemetry-event-relay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,22 +1155,6 @@ describe('TelemetryEventRelay', () => {
expect(telemetry.trackWorkflowExecution).not.toHaveBeenCalled();
});

it('should not track when execution status is "waiting"', async () => {
const event: RelayEventMap['workflow-post-execute'] = {
workflow: mockWorkflowBase,
executionId: 'execution123',
userId: 'user123',
runData: {
status: 'waiting',
data: { resultData: {} },
} as IRun,
};

eventService.emit('workflow-post-execute', event);

expect(telemetry.trackWorkflowExecution).not.toHaveBeenCalled();
});

it('should track successful workflow execution', async () => {
const runData = mock<IRun>({
finished: true,
Expand Down
5 changes: 0 additions & 5 deletions packages/cli/src/events/relays/telemetry.event-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,6 @@ export class TelemetryEventRelay extends EventRelay {
return;
}

if (runData?.status === 'waiting') {
// No need to send telemetry or logs when the workflow hasn't finished yet.
return;
}

const telemetryProperties: IExecutionTrackProperties = {
workflow_id: workflow.id,
is_manual: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ describe('Execution Lifecycle Hooks', () => {
workflow: workflowData,
});
});

it('should not emit workflow-post-execute events for waiting executions', async () => {
await hooks.executeHookFunctions('workflowExecuteAfter', [waitingRun, {}]);

expect(eventService.emit).not.toHaveBeenCalledWith('workflow-post-execute');
});
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function hookFunctionsWorkflowEvents(userId?: string): IWorkflowExecuteHooks {
],
workflowExecuteAfter: [
async function (this: WorkflowHooks, runData: IRun): Promise<void> {
if (runData.status === 'waiting') return;

const { executionId, workflowData: workflow } = this;
eventService.emit('workflow-post-execute', { executionId, runData, workflow, userId });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('ExecutionRecoveryService', () => {
instanceSettings,
push,
executionRepository,
mock(),
);
});

Expand Down
8 changes: 0 additions & 8 deletions packages/cli/src/executions/execution-recovery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ARTIFICIAL_TASK_DATA } from '@/constants';
import { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { NodeCrashedError } from '@/errors/node-crashed.error';
import { WorkflowCrashedError } from '@/errors/workflow-crashed.error';
import { EventService } from '@/events/event.service';
import { getWorkflowHooksMain } from '@/execution-lifecycle/execution-lifecycle-hooks';
import type { IExecutionResponse } from '@/interfaces';
import { Push } from '@/push';
Expand All @@ -25,7 +24,6 @@ export class ExecutionRecoveryService {
private readonly instanceSettings: InstanceSettings,
private readonly push: Push,
private readonly executionRepository: ExecutionRepository,
private readonly eventService: EventService,
) {}

/**
Expand Down Expand Up @@ -176,12 +174,6 @@ export class ExecutionRecoveryService {
private async runHooks(execution: IExecutionResponse) {
execution.data ??= { resultData: { runData: {} } };

this.eventService.emit('workflow-post-execute', {
workflow: execution.workflowData,
executionId: execution.id,
runData: execution,
});

const externalHooks = getWorkflowHooksMain(
{
userId: '',
Expand Down

0 comments on commit 1593b6c

Please sign in to comment.