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): Restore queue listeners for webhook process #10781

Merged
merged 1 commit into from
Sep 12, 2024
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
28 changes: 22 additions & 6 deletions packages/cli/src/scaling/__tests__/scaling.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('ScalingService', () => {

let scalingService: ScalingService;

let registerMainListenersSpy: jest.SpyInstance;
let registerMainOrWebhookListenersSpy: jest.SpyInstance;
let registerWorkerListenersSpy: jest.SpyInstance;
let scheduleQueueRecoverySpy: jest.SpyInstance;
let stopQueueRecoverySpy: jest.SpyInstance;
Expand Down Expand Up @@ -86,8 +86,11 @@ describe('ScalingService', () => {

// @ts-expect-error Private method
ScalingService.prototype.scheduleQueueRecovery = jest.fn();
// @ts-expect-error Private method
registerMainListenersSpy = jest.spyOn(scalingService, 'registerMainListeners');
registerMainOrWebhookListenersSpy = jest.spyOn(
scalingService,
// @ts-expect-error Private method
'registerMainOrWebhookListeners',
);
// @ts-expect-error Private method
registerWorkerListenersSpy = jest.spyOn(scalingService, 'registerWorkerListeners');
// @ts-expect-error Private method
Expand All @@ -102,7 +105,7 @@ describe('ScalingService', () => {
await scalingService.setupQueue();

expect(Bull).toHaveBeenCalledWith(...bullConstructorArgs);
expect(registerMainListenersSpy).toHaveBeenCalled();
expect(registerMainOrWebhookListenersSpy).toHaveBeenCalled();
expect(registerWorkerListenersSpy).not.toHaveBeenCalled();
expect(scheduleQueueRecoverySpy).toHaveBeenCalled();
});
Expand All @@ -115,7 +118,7 @@ describe('ScalingService', () => {
await scalingService.setupQueue();

expect(Bull).toHaveBeenCalledWith(...bullConstructorArgs);
expect(registerMainListenersSpy).toHaveBeenCalled();
expect(registerMainOrWebhookListenersSpy).toHaveBeenCalled();
expect(registerWorkerListenersSpy).not.toHaveBeenCalled();
expect(scheduleQueueRecoverySpy).not.toHaveBeenCalled();
});
Expand All @@ -130,7 +133,20 @@ describe('ScalingService', () => {

expect(Bull).toHaveBeenCalledWith(...bullConstructorArgs);
expect(registerWorkerListenersSpy).toHaveBeenCalled();
expect(registerMainListenersSpy).not.toHaveBeenCalled();
expect(registerMainOrWebhookListenersSpy).not.toHaveBeenCalled();
});
});

describe('webhook', () => {
it('should set up a queue + listeners', async () => {
// @ts-expect-error Private field
scalingService.instanceType = 'webhook';

await scalingService.setupQueue();

expect(Bull).toHaveBeenCalledWith(...bullConstructorArgs);
expect(registerWorkerListenersSpy).not.toHaveBeenCalled();
expect(registerMainOrWebhookListenersSpy).toHaveBeenCalled();
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/scaling/scaling.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ export class ScalingService {
throw error;
});

if (this.instanceType === 'main') {
this.registerMainListeners();
if (this.instanceType === 'main' || this.instanceType === 'webhook') {
this.registerMainOrWebhookListeners();
} else if (this.instanceType === 'worker') {
this.registerWorkerListeners();
}
Expand Down Expand Up @@ -246,9 +246,9 @@ export class ScalingService {
}

/**
* Register listeners on a `main` process for Bull queue events.
* Register listeners on a `main` or `webhook` process for Bull queue events.
*/
private registerMainListeners() {
private registerMainOrWebhookListeners() {
this.queue.on('global:progress', (_jobId: JobId, msg: unknown) => {
if (!this.isPubSubMessage(msg)) return;

Expand Down
Loading