Skip to content

Commit

Permalink
fix(omnichannel): stop calling an object through proxy (#33719)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Oct 23, 2024
1 parent 82767d8 commit 63ccadc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .changeset/smart-radios-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/core-services": patch
---

stops calling an object through proxy calling getQueueWorker
14 changes: 1 addition & 13 deletions apps/meteor/app/livechat/server/lib/RoutingManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Apps, AppEvents } from '@rocket.chat/apps';
import { Message, Omnichannel } from '@rocket.chat/core-services';
import { Message } from '@rocket.chat/core-services';
import type {
ILivechatInquiryRecord,
ILivechatVisitor,
Expand All @@ -12,7 +12,6 @@ import type {
TransferData,
} from '@rocket.chat/core-typings';
import { LivechatInquiryStatus } from '@rocket.chat/core-typings';
import { License } from '@rocket.chat/license';
import { Logger } from '@rocket.chat/logger';
import { LivechatInquiry, LivechatRooms, Subscriptions, Rooms, Users } from '@rocket.chat/models';
import { Match, check } from 'meteor/check';
Expand All @@ -36,7 +35,6 @@ const logger = new Logger('RoutingManager');

type Routing = {
methods: Record<string, IRoutingMethod>;
startQueue(): Promise<void>;
isMethodSet(): boolean;
registerMethod(name: string, Method: IRoutingMethodConstructor): void;
getMethod(): IRoutingMethod;
Expand Down Expand Up @@ -68,16 +66,6 @@ type Routing = {
export const RoutingManager: Routing = {
methods: {},

async startQueue() {
const shouldPreventQueueStart = await License.shouldPreventAction('monthlyActiveContacts');

if (shouldPreventQueueStart) {
logger.error('Monthly Active Contacts limit reached. Queue will not start');
return;
}
void (await Omnichannel.getQueueWorker()).shouldStart();
},

isMethodSet() {
return settings.get<string>('Livechat_Routing_Method') !== '';
},
Expand Down
5 changes: 0 additions & 5 deletions apps/meteor/app/livechat/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { settings } from '../../settings/server';
import { businessHourManager } from './business-hour';
import { createDefaultBusinessHourIfNotExists } from './business-hour/Helper';
import { Livechat as LivechatTyped } from './lib/LivechatTyped';
import { RoutingManager } from './lib/RoutingManager';
import { LivechatAgentActivityMonitor } from './statistics/LivechatAgentActivityMonitor';
import './roomAccessValidator.internalService';

Expand Down Expand Up @@ -82,10 +81,6 @@ Meteor.startup(async () => {
: undefined,
);

settings.watch<string>('Livechat_Routing_Method', () => {
void RoutingManager.startQueue();
});

// Remove when accounts.onLogout is async
Accounts.onLogout(({ user }: { user?: IUser }) => {
if (!user?.roles?.includes('livechat-agent') || user?.roles?.includes('bot')) {
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/server/services/omnichannel/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha
void (enabled && RoutingManager.isMethodSet() ? this.queueWorker.shouldStart() : this.queueWorker.stop());
});

settings.watch<string>('Livechat_Routing_Method', async () => {
this.queueWorker.shouldStart();
});

License.onLimitReached('monthlyActiveContacts', async (): Promise<void> => {
this.queueWorker.isRunning() && (await this.queueWorker.stop());
});
Expand All @@ -52,10 +56,6 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha
});
}

getQueueWorker(): IOmnichannelQueue {
return this.queueWorker;
}

async isWithinMACLimit(room: AtLeast<IOmnichannelRoom, 'v'>): Promise<boolean> {
const currentMonth = moment.utc().format('YYYY-MM');
return room.v?.activity?.includes(currentMonth) || !(await License.shouldPreventAction('monthlyActiveContacts'));
Expand Down
3 changes: 1 addition & 2 deletions packages/core-services/src/types/IOmnichannelService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { AtLeast, IOmnichannelQueue, IOmnichannelRoom } from '@rocket.chat/core-typings';
import type { AtLeast, IOmnichannelRoom } from '@rocket.chat/core-typings';

import type { IServiceClass } from './ServiceClass';

export interface IOmnichannelService extends IServiceClass {
getQueueWorker(): IOmnichannelQueue;
isWithinMACLimit(_room: AtLeast<IOmnichannelRoom, 'v'>): Promise<boolean>;
}

0 comments on commit 63ccadc

Please sign in to comment.