Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Prevent workers from recovering executions on startup #11310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class MessageEventBus extends EventEmitter {

// if we are in queue mode, running jobs may still be running on a worker despite the main process
// crashing, so we can't just mark them as crashed
if (config.get('executions.mode') !== 'queue') {
if (config.get('executions.mode') === 'regular') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability

const dbUnfinishedExecutionIds = (
await this.executionRepository.find({
where: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ describe('ExecutionRecoveryService', () => {
});

describe('recoverFromLogs', () => {
describe('if not main', () => {
test('should do nothing', async () => {
const executionRecoveryService = new ExecutionRecoveryService(
mock(),
mock<InstanceSettings>({ instanceType: 'worker' }),
push,
executionRepository,
mock(),
);
// @ts-expect-error Private method
const amendSpy = jest.spyOn(executionRecoveryService, 'amend');
const messages = setupMessages('123', 'Some workflow');

/**
* Act
*/
await executionRecoveryService.recoverFromLogs('123', messages);

/**
* Assert
*/
expect(amendSpy).not.toHaveBeenCalled();
});
});

describe('if follower', () => {
test('should do nothing', async () => {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/executions/execution-recovery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { EventService } from '@/events/event.service';
import type { IExecutionResponse } from '@/interfaces';
import { Logger } from '@/logging/logger.service';
import { Push } from '@/push';
import { getWorkflowHooksMain } from '@/workflow-execute-additional-data'; // @TODO: Dependency cycle
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

import { getWorkflowHooksMain } from '@/workflow-execute-additional-data';

import type { EventMessageTypes } from '../eventbus/event-message-classes';

Expand All @@ -33,7 +33,7 @@ export class ExecutionRecoveryService {
* Recover key properties of a truncated execution using event logs.
*/
async recoverFromLogs(executionId: string, messages: EventMessageTypes[]) {
if (this.instanceSettings.isFollower) return;
if (this.instanceSettings.instanceType !== 'main' || this.instanceSettings.isFollower) return;

const amendedExecution = await this.amend(executionId, messages);

Expand Down
Loading