mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Fix push message type inference (#12331)
This commit is contained in:
@@ -620,7 +620,10 @@ describe('PubSubHandler', () => {
|
||||
expect(activeWorkflowManager.add).toHaveBeenCalledWith(workflowId, 'activate', undefined, {
|
||||
shouldPublish: false,
|
||||
});
|
||||
expect(push.broadcast).toHaveBeenCalledWith('workflowActivated', { workflowId });
|
||||
expect(push.broadcast).toHaveBeenCalledWith({
|
||||
type: 'workflowActivated',
|
||||
data: { workflowId },
|
||||
});
|
||||
expect(publisher.publishCommand).toHaveBeenCalledWith({
|
||||
command: 'display-workflow-activation',
|
||||
payload: { workflowId },
|
||||
@@ -680,7 +683,10 @@ describe('PubSubHandler', () => {
|
||||
expect(activeWorkflowManager.removeWorkflowTriggersAndPollers).toHaveBeenCalledWith(
|
||||
workflowId,
|
||||
);
|
||||
expect(push.broadcast).toHaveBeenCalledWith('workflowDeactivated', { workflowId });
|
||||
expect(push.broadcast).toHaveBeenCalledWith({
|
||||
type: 'workflowDeactivated',
|
||||
data: { workflowId },
|
||||
});
|
||||
expect(publisher.publishCommand).toHaveBeenCalledWith({
|
||||
command: 'display-workflow-deactivation',
|
||||
payload: { workflowId },
|
||||
@@ -735,7 +741,10 @@ describe('PubSubHandler', () => {
|
||||
|
||||
eventService.emit('display-workflow-activation', { workflowId });
|
||||
|
||||
expect(push.broadcast).toHaveBeenCalledWith('workflowActivated', { workflowId });
|
||||
expect(push.broadcast).toHaveBeenCalledWith({
|
||||
type: 'workflowActivated',
|
||||
data: { workflowId },
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle `display-workflow-deactivation` event', () => {
|
||||
@@ -758,7 +767,10 @@ describe('PubSubHandler', () => {
|
||||
|
||||
eventService.emit('display-workflow-deactivation', { workflowId });
|
||||
|
||||
expect(push.broadcast).toHaveBeenCalledWith('workflowDeactivated', { workflowId });
|
||||
expect(push.broadcast).toHaveBeenCalledWith({
|
||||
type: 'workflowDeactivated',
|
||||
data: { workflowId },
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle `display-workflow-activation-error` event', () => {
|
||||
@@ -782,9 +794,12 @@ describe('PubSubHandler', () => {
|
||||
|
||||
eventService.emit('display-workflow-activation-error', { workflowId, errorMessage });
|
||||
|
||||
expect(push.broadcast).toHaveBeenCalledWith('workflowFailedToActivate', {
|
||||
workflowId,
|
||||
errorMessage,
|
||||
expect(push.broadcast).toHaveBeenCalledWith({
|
||||
type: 'workflowFailedToActivate',
|
||||
data: {
|
||||
workflowId,
|
||||
errorMessage,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -806,15 +821,21 @@ describe('PubSubHandler', () => {
|
||||
|
||||
const pushRef = 'test-push-ref';
|
||||
const type = 'executionStarted';
|
||||
const args = { testArg: 'value' };
|
||||
const data = {
|
||||
executionId: '123',
|
||||
mode: 'webhook' as const,
|
||||
startedAt: new Date(),
|
||||
workflowId: '456',
|
||||
flattedRunData: '[]',
|
||||
};
|
||||
|
||||
push.getBackend.mockReturnValue(
|
||||
mock<WebSocketPush>({ hasPushRef: jest.fn().mockReturnValue(true) }),
|
||||
);
|
||||
|
||||
eventService.emit('relay-execution-lifecycle-event', { type, args, pushRef });
|
||||
eventService.emit('relay-execution-lifecycle-event', { type, data, pushRef });
|
||||
|
||||
expect(push.send).toHaveBeenCalledWith(type, args, pushRef);
|
||||
expect(push.send).toHaveBeenCalledWith({ type, data }, pushRef);
|
||||
});
|
||||
|
||||
it('should handle `clear-test-webhooks` event', () => {
|
||||
@@ -868,9 +889,12 @@ describe('PubSubHandler', () => {
|
||||
|
||||
eventService.emit('response-to-get-worker-status', workerStatus);
|
||||
|
||||
expect(push.broadcast).toHaveBeenCalledWith('sendWorkerStatusMessage', {
|
||||
workerId: workerStatus.senderId,
|
||||
status: workerStatus,
|
||||
expect(push.broadcast).toHaveBeenCalledWith({
|
||||
type: 'sendWorkerStatusMessage',
|
||||
data: {
|
||||
workerId: workerStatus.senderId,
|
||||
status: workerStatus,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,10 +65,10 @@ export class Publisher {
|
||||
const metadata: LogMetadata = { msg: msg.command, channel: 'n8n.commands' };
|
||||
|
||||
if (msg.command === 'relay-execution-lifecycle-event') {
|
||||
const { args, type } = msg.payload;
|
||||
const { data, type } = msg.payload;
|
||||
msgName += ` (${type})`;
|
||||
metadata.type = type;
|
||||
metadata.executionId = args.executionId;
|
||||
if ('executionId' in data) metadata.executionId = data.executionId;
|
||||
}
|
||||
|
||||
this.logger.debug(`Published pubsub msg: ${msgName}`, metadata);
|
||||
|
||||
@@ -59,9 +59,12 @@ export class PubSubHandler {
|
||||
...this.commonHandlers,
|
||||
...this.multiMainHandlers,
|
||||
'response-to-get-worker-status': async (payload) =>
|
||||
this.push.broadcast('sendWorkerStatusMessage', {
|
||||
workerId: payload.senderId,
|
||||
status: payload,
|
||||
this.push.broadcast({
|
||||
type: 'sendWorkerStatusMessage',
|
||||
data: {
|
||||
workerId: payload.senderId,
|
||||
status: payload,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -113,7 +116,7 @@ export class PubSubHandler {
|
||||
shouldPublish: false, // prevent leader from re-publishing message
|
||||
});
|
||||
|
||||
this.push.broadcast('workflowActivated', { workflowId });
|
||||
this.push.broadcast({ type: 'workflowActivated', data: { workflowId } });
|
||||
|
||||
await this.publisher.publishCommand({
|
||||
command: 'display-workflow-activation',
|
||||
@@ -125,7 +128,10 @@ export class PubSubHandler {
|
||||
|
||||
await this.workflowRepository.update(workflowId, { active: false });
|
||||
|
||||
this.push.broadcast('workflowFailedToActivate', { workflowId, errorMessage: message });
|
||||
this.push.broadcast({
|
||||
type: 'workflowFailedToActivate',
|
||||
data: { workflowId, errorMessage: message },
|
||||
});
|
||||
|
||||
await this.publisher.publishCommand({
|
||||
command: 'display-workflow-activation-error',
|
||||
@@ -139,7 +145,7 @@ export class PubSubHandler {
|
||||
await this.activeWorkflowManager.removeActivationError(workflowId);
|
||||
await this.activeWorkflowManager.removeWorkflowTriggersAndPollers(workflowId);
|
||||
|
||||
this.push.broadcast('workflowDeactivated', { workflowId });
|
||||
this.push.broadcast({ type: 'workflowDeactivated', data: { workflowId } });
|
||||
|
||||
// instruct followers to show workflow deactivation in UI
|
||||
await this.publisher.publishCommand({
|
||||
@@ -148,15 +154,15 @@ export class PubSubHandler {
|
||||
});
|
||||
},
|
||||
'display-workflow-activation': async ({ workflowId }) =>
|
||||
this.push.broadcast('workflowActivated', { workflowId }),
|
||||
this.push.broadcast({ type: 'workflowActivated', data: { workflowId } }),
|
||||
'display-workflow-deactivation': async ({ workflowId }) =>
|
||||
this.push.broadcast('workflowDeactivated', { workflowId }),
|
||||
this.push.broadcast({ type: 'workflowDeactivated', data: { workflowId } }),
|
||||
'display-workflow-activation-error': async ({ workflowId, errorMessage }) =>
|
||||
this.push.broadcast('workflowFailedToActivate', { workflowId, errorMessage }),
|
||||
'relay-execution-lifecycle-event': async ({ type, args, pushRef }) => {
|
||||
this.push.broadcast({ type: 'workflowFailedToActivate', data: { workflowId, errorMessage } }),
|
||||
'relay-execution-lifecycle-event': async ({ pushRef, ...pushMsg }) => {
|
||||
if (!this.push.getBackend().hasPushRef(pushRef)) return;
|
||||
|
||||
this.push.send(type, args, pushRef);
|
||||
this.push.send(pushMsg, pushRef);
|
||||
},
|
||||
'clear-test-webhooks': async ({ webhookKey, workflowEntity, pushRef }) => {
|
||||
if (!this.push.getBackend().hasPushRef(pushRef)) return;
|
||||
|
||||
@@ -95,10 +95,10 @@ export class Subscriber {
|
||||
const metadata: LogMetadata = { msg: msgName, channel };
|
||||
|
||||
if ('command' in msg && msg.command === 'relay-execution-lifecycle-event') {
|
||||
const { args, type } = msg.payload;
|
||||
const { data, type } = msg.payload;
|
||||
msgName += ` (${type})`;
|
||||
metadata.type = type;
|
||||
metadata.executionId = args.executionId;
|
||||
if ('executionId' in data) metadata.executionId = data.executionId;
|
||||
}
|
||||
|
||||
this.logger.debug(`Received pubsub msg: ${msgName}`, metadata);
|
||||
|
||||
Reference in New Issue
Block a user