Skip to content

Commit

Permalink
stop calling an object through proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Oct 23, 2024
1 parent b4aeae1 commit 124f1f2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
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
4 changes: 0 additions & 4 deletions apps/meteor/app/livechat/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,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
10 changes: 6 additions & 4 deletions apps/meteor/server/services/omnichannel/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha

constructor() {
super();

this.queueWorker = new OmnichannelQueue();
console.log('new OmnichannelQueue', this.queueWorker);
}

async created() {
Expand All @@ -37,6 +39,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 +58,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 124f1f2

Please sign in to comment.