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): Account for activation error caused by follower main instance #7735

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
13 changes: 12 additions & 1 deletion packages/cli/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,13 @@ export type IPushData =
| PushDataActiveWorkflowUsersChanged
| PushDataWorkerStatusMessage
| PushDataWorkflowActivated
| PushDataWorkflowDeactivated;
| PushDataWorkflowDeactivated
| PushDataWorkflowFailedToActivate;

type PushDataWorkflowFailedToActivate = {
data: IWorkflowFailedToActivate;
type: 'workflowFailedToActivate';
};

type PushDataWorkflowActivated = {
data: IActiveWorkflowChanged;
Expand Down Expand Up @@ -561,6 +567,11 @@ interface IActiveWorkflowChanged {
workflowId: Workflow['id'];
}

interface IWorkflowFailedToActivate {
workflowId: Workflow['id'];
errorMessage: string;
}

export interface IPushDataExecutionRecovered {
executionId: string;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/services/orchestration/main/MultiMainSetup.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class MultiMainSetup extends SingleMainSetup {
workflowId: string;
oldState: boolean;
newState: boolean;
versionId: string;
}) {
if (!this.sanityCheck()) return;

Expand All @@ -120,4 +121,13 @@ export class MultiMainSetup extends SingleMainSetup {
payload,
});
}

async broadcastWorkflowFailedToActivate(payload: { workflowId: string; errorMessage: string }) {
if (!this.sanityCheck()) return;

await this.redisPublisher.publishToCommandChannel({
command: 'workflowFailedToActivate',
payload,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { License } from '@/License';
import { Logger } from '@/Logger';
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
import { Push } from '@/push';
import { MultiMainSetup } from './MultiMainSetup.ee';
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';

export async function handleCommandMessageMain(messageString: string) {
const queueModeId = config.getEnv('redis.queueModeId');
Expand Down Expand Up @@ -71,21 +73,36 @@ export async function handleCommandMessageMain(messageString: string) {
return message;
}

const { workflowId, oldState, newState } = message.payload ?? {};
const { workflowId, oldState, newState, versionId } = message.payload ?? {};

if (
typeof workflowId !== 'string' ||
typeof oldState !== 'boolean' ||
typeof newState !== 'boolean'
typeof newState !== 'boolean' ||
typeof versionId !== 'string'
) {
break;
}

const push = Container.get(Push);

if (!oldState && newState) {
await activeWorkflowRunner.add(workflowId, 'activate');
push.broadcast('workflowActivated', { workflowId });
try {
await activeWorkflowRunner.add(workflowId, 'activate');
push.broadcast('workflowActivated', { workflowId });
} catch (e) {
const error = e instanceof Error ? e : new Error(`${e}`);

await Container.get(WorkflowRepository).update(workflowId, {
active: false,
versionId,
});

await Container.get(MultiMainSetup).broadcastWorkflowFailedToActivate({
workflowId,
errorMessage: error.message,
});
}
} else if (oldState && !newState) {
await activeWorkflowRunner.remove(workflowId);
push.broadcast('workflowDeactivated', { workflowId });
Expand All @@ -97,6 +114,19 @@ export async function handleCommandMessageMain(messageString: string) {
await activeWorkflowRunner.removeActivationError(workflowId);
}

case 'workflowFailedToActivate': {
if (!debounceMessageReceiver(message, 100)) {
message.payload = { result: 'debounced' };
return message;
}

const { workflowId, errorMessage } = message.payload ?? {};

if (typeof workflowId !== 'string' || typeof errorMessage !== 'string') break;

Container.get(Push).broadcast('workflowFailedToActivate', { workflowId, errorMessage });
}

default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/services/redis/RedisServiceCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type RedisServiceCommand =
| 'stopWorker'
| 'reloadLicense'
| 'reloadExternalSecretsProviders'
| 'workflowActiveStateChanged'; // multi-main only
| 'workflowActiveStateChanged' // multi-main only
| 'workflowFailedToActivate'; // multi-main only

/**
* An object to be sent via Redis pub/sub from the main process to the workers.
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/workflows/workflows.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export class WorkflowsService {
workflowId,
oldState,
newState: updatedWorkflow.active,
versionId: shared.workflow.versionId,
});
}
}
Expand Down
13 changes: 12 additions & 1 deletion packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ export type IPushData =
| PushDataExecutionRecovered
| PushDataWorkerStatusMessage
| PushDataActiveWorkflowAdded
| PushDataActiveWorkflowRemoved;
| PushDataActiveWorkflowRemoved
| PushDataWorkflowFailedToActivate;

type PushDataActiveWorkflowAdded = {
data: IActiveWorkflowAdded;
Expand All @@ -433,6 +434,11 @@ type PushDataActiveWorkflowRemoved = {
type: 'workflowDeactivated';
};

type PushDataWorkflowFailedToActivate = {
data: IWorkflowFailedToActivate;
type: 'workflowFailedToActivate';
};

type PushDataExecutionRecovered = {
data: IPushDataExecutionRecovered;
type: 'executionRecovered';
Expand Down Expand Up @@ -509,6 +515,11 @@ export interface IActiveWorkflowRemoved {
workflowId: string;
}

export interface IWorkflowFailedToActivate {
workflowId: string;
errorMessage: string;
}

export interface IPushDataUnsavedExecutionFinished {
executionId: string;
data: { finished: true; stoppedAt: Date };
Expand Down
14 changes: 14 additions & 0 deletions packages/editor-ui/src/mixins/pushConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ export const pushConnection = defineComponent({
}
}

if (receivedData.type === 'workflowFailedToActivate') {
this.workflowsStore.setWorkflowInactive(receivedData.data.workflowId);
this.workflowsStore.setActive(false);

this.showError(
new Error(receivedData.data.errorMessage),
this.$locale.baseText('workflowActivator.showError.title', {
interpolate: { newStateName: 'deactivated' },
}) + ':',
);

return true;
}

if (receivedData.type === 'workflowActivated') {
this.workflowsStore.setWorkflowActive(receivedData.data.workflowId);
return true;
Expand Down
Loading