From 63ccadc012499e004445ad6bc6cd2ff777aecbd1 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 23 Oct 2024 14:26:30 -0300 Subject: [PATCH] fix(omnichannel): stop calling an object through proxy (#33719) --- .changeset/smart-radios-reflect.md | 6 ++++++ .../app/livechat/server/lib/RoutingManager.ts | 14 +------------- apps/meteor/app/livechat/server/startup.ts | 5 ----- apps/meteor/server/services/omnichannel/service.ts | 8 ++++---- .../core-services/src/types/IOmnichannelService.ts | 3 +-- 5 files changed, 12 insertions(+), 24 deletions(-) create mode 100644 .changeset/smart-radios-reflect.md diff --git a/.changeset/smart-radios-reflect.md b/.changeset/smart-radios-reflect.md new file mode 100644 index 000000000000..58ea7413e51c --- /dev/null +++ b/.changeset/smart-radios-reflect.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/core-services": patch +--- + +stops calling an object through proxy calling getQueueWorker diff --git a/apps/meteor/app/livechat/server/lib/RoutingManager.ts b/apps/meteor/app/livechat/server/lib/RoutingManager.ts index 28e5c72efc16..8781f675ebf9 100644 --- a/apps/meteor/app/livechat/server/lib/RoutingManager.ts +++ b/apps/meteor/app/livechat/server/lib/RoutingManager.ts @@ -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, @@ -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'; @@ -36,7 +35,6 @@ const logger = new Logger('RoutingManager'); type Routing = { methods: Record; - startQueue(): Promise; isMethodSet(): boolean; registerMethod(name: string, Method: IRoutingMethodConstructor): void; getMethod(): IRoutingMethod; @@ -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('Livechat_Routing_Method') !== ''; }, diff --git a/apps/meteor/app/livechat/server/startup.ts b/apps/meteor/app/livechat/server/startup.ts index 32cf01d2e640..994dcd64f52a 100644 --- a/apps/meteor/app/livechat/server/startup.ts +++ b/apps/meteor/app/livechat/server/startup.ts @@ -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'; @@ -82,10 +81,6 @@ Meteor.startup(async () => { : undefined, ); - settings.watch('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')) { diff --git a/apps/meteor/server/services/omnichannel/service.ts b/apps/meteor/server/services/omnichannel/service.ts index 34599cbc7a33..437baa2f63ee 100644 --- a/apps/meteor/server/services/omnichannel/service.ts +++ b/apps/meteor/server/services/omnichannel/service.ts @@ -37,6 +37,10 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha void (enabled && RoutingManager.isMethodSet() ? this.queueWorker.shouldStart() : this.queueWorker.stop()); }); + settings.watch('Livechat_Routing_Method', async () => { + this.queueWorker.shouldStart(); + }); + License.onLimitReached('monthlyActiveContacts', async (): Promise => { this.queueWorker.isRunning() && (await this.queueWorker.stop()); }); @@ -52,10 +56,6 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha }); } - getQueueWorker(): IOmnichannelQueue { - return this.queueWorker; - } - async isWithinMACLimit(room: AtLeast): Promise { const currentMonth = moment.utc().format('YYYY-MM'); return room.v?.activity?.includes(currentMonth) || !(await License.shouldPreventAction('monthlyActiveContacts')); diff --git a/packages/core-services/src/types/IOmnichannelService.ts b/packages/core-services/src/types/IOmnichannelService.ts index 73006641c8cd..ac2a1eb57765 100644 --- a/packages/core-services/src/types/IOmnichannelService.ts +++ b/packages/core-services/src/types/IOmnichannelService.ts @@ -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): Promise; }