Skip to content

Commit

Permalink
fix(core): Fix resuming executions on test webhooks from Wait nodes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Feb 10, 2025
1 parent 8f25a06 commit 5dddf77
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/cli/src/webhooks/__tests__/waiting-webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ConflictError } from '@/errors/response-errors/conflict.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import type { IExecutionResponse } from '@/interfaces';
import { WaitingWebhooks } from '@/webhooks/waiting-webhooks';
import type { WaitingWebhookRequest } from '@/webhooks/webhook.types';
import type { IWebhookResponseCallbackData, WaitingWebhookRequest } from '@/webhooks/webhook.types';

describe('WaitingWebhooks', () => {
const executionRepository = mock<ExecutionRepository>();
Expand Down Expand Up @@ -79,4 +79,25 @@ describe('WaitingWebhooks', () => {
*/
await expect(promise).rejects.toThrowError(ConflictError);
});

it('should mark as test webhook when execution mode is manual', async () => {
jest
// @ts-expect-error Protected method
.spyOn(waitingWebhooks, 'getWebhookExecutionData')
// @ts-expect-error Protected method
.mockResolvedValue(mock<IWebhookResponseCallbackData>());

const execution = mock<IExecutionResponse>({
finished: false,
mode: 'manual',
data: {
resultData: { lastNodeExecuted: 'someNode', error: undefined },
},
});
executionRepository.findSingleExecution.mockResolvedValue(execution);

await waitingWebhooks.executeWebhook(mock<WaitingWebhookRequest>(), mock<express.Response>());

expect(execution.data.isTestWebhook).toBe(true);
});
});
6 changes: 6 additions & 0 deletions packages/cli/src/webhooks/waiting-webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export class WaitingWebhooks implements IWebhookManager {

const lastNodeExecuted = execution.data.resultData.lastNodeExecuted as string;

/**
* A manual execution resumed by a webhook call needs to be marked as such
* so workers in scaling mode reuse the existing execution data.
*/
if (execution.mode === 'manual') execution.data.isTestWebhook = true;

return await this.getWebhookExecutionData({
execution,
req,
Expand Down

0 comments on commit 5dddf77

Please sign in to comment.