mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
fix: Always register webhooks on startup (#8830)
This commit is contained in:
parent
c8d589cce7
commit
c6f6254c0e
|
@ -128,7 +128,11 @@ export class OrchestrationService {
|
||||||
* Whether this instance may add webhooks to the `webhook_entity` table.
|
* Whether this instance may add webhooks to the `webhook_entity` table.
|
||||||
*/
|
*/
|
||||||
shouldAddWebhooks(activationMode: WorkflowActivateMode) {
|
shouldAddWebhooks(activationMode: WorkflowActivateMode) {
|
||||||
if (activationMode === 'init') return false;
|
// Always try to populate the webhook entity table as well as register the webhooks
|
||||||
|
// to prevent issues with users upgrading from a version < 1.15, where the webhook entity
|
||||||
|
// was cleared on shutdown to anything past 1.28.0, where we stopped populating it on init,
|
||||||
|
// causing all webhooks to break
|
||||||
|
if (activationMode === 'init') return true;
|
||||||
|
|
||||||
if (activationMode === 'leadershipChange') return false;
|
if (activationMode === 'leadershipChange') return false;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { Logger } from '@/Logger';
|
||||||
import { Push } from '@/push';
|
import { Push } from '@/push';
|
||||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||||
import { mockInstance } from '../../shared/mocking';
|
import { mockInstance } from '../../shared/mocking';
|
||||||
|
import type { WorkflowActivateMode } from 'n8n-workflow';
|
||||||
|
|
||||||
const os = Container.get(OrchestrationService);
|
const os = Container.get(OrchestrationService);
|
||||||
const handler = Container.get(OrchestrationHandlerMainService);
|
const handler = Container.get(OrchestrationHandlerMainService);
|
||||||
|
@ -149,4 +150,38 @@ describe('Orchestration Service', () => {
|
||||||
expect(res1!.payload).toBeUndefined();
|
expect(res1!.payload).toBeUndefined();
|
||||||
expect(res2!.payload!.result).toEqual('debounced');
|
expect(res2!.payload!.result).toEqual('debounced');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('shouldAddWebhooks', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
config.set('multiMainSetup.instanceType', 'leader');
|
||||||
|
});
|
||||||
|
test('should return true for init', () => {
|
||||||
|
// We want to ensure that webhooks are populated on init
|
||||||
|
// more https://github.com/n8n-io/n8n/pull/8830
|
||||||
|
const result = os.shouldAddWebhooks('init');
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return false for leadershipChange', () => {
|
||||||
|
const result = os.shouldAddWebhooks('leadershipChange');
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return true for update or activate when is leader', () => {
|
||||||
|
const modes = ['update', 'activate'] as WorkflowActivateMode[];
|
||||||
|
for (const mode of modes) {
|
||||||
|
const result = os.shouldAddWebhooks(mode);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return false for update or activate when not leader', () => {
|
||||||
|
config.set('multiMainSetup.instanceType', 'follower');
|
||||||
|
const modes = ['update', 'activate'] as WorkflowActivateMode[];
|
||||||
|
for (const mode of modes) {
|
||||||
|
const result = os.shouldAddWebhooks(mode);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue