Skip to content

Commit 2cc2a7c

Browse files
committed
refactor: consolidate queue services and modules
1 parent 25d3977 commit 2cc2a7c

File tree

209 files changed

+2384
-3417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+2384
-3417
lines changed

libs/contract/constants/events/events.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export const EVENTS = {
99
LIMITED: 'user.limited',
1010
EXPIRED: 'user.expired',
1111
TRAFFIC_RESET: 'user.traffic_reset',
12-
EXPIRE_NOTIFY: {
13-
EXPIRES_IN_72_HOURS: 'user.expires_in_72_hours',
14-
EXPIRES_IN_48_HOURS: 'user.expires_in_48_hours',
15-
EXPIRES_IN_24_HOURS: 'user.expires_in_24_hours',
16-
EXPIRED_24_HOURS_AGO: 'user.expired_24_hours_ago',
17-
},
12+
13+
EXPIRE_NOTIFY_EXPIRES_IN_72_HOURS: 'user.expires_in_72_hours',
14+
EXPIRE_NOTIFY_EXPIRES_IN_48_HOURS: 'user.expires_in_48_hours',
15+
EXPIRE_NOTIFY_EXPIRES_IN_24_HOURS: 'user.expires_in_24_hours',
16+
EXPIRE_NOTIFY_EXPIRED_24_HOURS_AGO: 'user.expired_24_hours_ago',
17+
1818
FIRST_CONNECTED: 'user.first_connected',
1919
BANDWIDTH_USAGE_THRESHOLD_REACHED: 'user.bandwidth_usage_threshold_reached',
2020
/**

libs/contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@remnawave/backend-contract",
3-
"version": "2.3.28",
3+
"version": "2.3.29",
44
"public": true,
55
"license": "AGPL-3.0-only",
66
"description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",

package-lock.json

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"@willsoto/nestjs-prometheus": "^6.0.2",
8989
"arctic": "^3.7.0",
9090
"axios": "^1.13.2",
91-
"bullmq": "5.63.2",
91+
"bullmq": "5.65.0",
9292
"cache-manager": "^7.2.5",
9393
"class-transformer": "^0.5.1",
9494
"compression": "^1.8.1",
@@ -141,7 +141,7 @@
141141
"zod": "^3.25.76"
142142
},
143143
"devDependencies": {
144-
"@nestjs/cli": "11.0.13",
144+
"@nestjs/cli": "11.0.14",
145145
"@nestjs/schematics": "11.0.9",
146146
"@types/compression": "^1.8.1",
147147
"@types/cookie-parser": "^1.4.10",

src/common/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from './certs';
22
export * from './convert-type';
33
export * from './happ-crypto-link';
44
export * from './mask-string';
5+
export * from './md5';
56
export * from './superjson';

src/common/utils/md5.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createHash } from 'node:crypto';
2+
3+
export function md5(data: string): string {
4+
return createHash('md5').update(data).digest('hex');
5+
}

src/integration-modules/notifications/telegram-bot/events/users/users.events.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class UsersEvents {
179179
});
180180
}
181181

182-
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY.EXPIRES_IN_72_HOURS)
182+
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY_EXPIRES_IN_72_HOURS)
183183
@RequireAdminId()
184184
async onUserExpiresIn72Hours(event: UserEvent): Promise<void> {
185185
const msg = `
@@ -194,7 +194,7 @@ export class UsersEvents {
194194
});
195195
}
196196

197-
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY.EXPIRES_IN_48_HOURS)
197+
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY_EXPIRES_IN_48_HOURS)
198198
@RequireAdminId()
199199
async onUserExpiresIn48Hours(event: UserEvent): Promise<void> {
200200
const msg = `
@@ -209,7 +209,7 @@ export class UsersEvents {
209209
});
210210
}
211211

212-
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY.EXPIRES_IN_24_HOURS)
212+
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY_EXPIRES_IN_24_HOURS)
213213
@RequireAdminId()
214214
async onUserExpiresIn24Hours(event: UserEvent): Promise<void> {
215215
const msg = `
@@ -224,7 +224,7 @@ export class UsersEvents {
224224
});
225225
}
226226

227-
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY.EXPIRED_24_HOURS_AGO)
227+
@OnEvent(EVENTS.USER.EXPIRE_NOTIFY_EXPIRED_24_HOURS_AGO)
228228
@RequireAdminId()
229229
async onUserExpired24HoursAgo(event: UserEvent): Promise<void> {
230230
const msg = `

src/modules/config-profiles/config-profile.service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { ICommandResponse } from '@common/types/command-response.type';
99
import { XRayConfig } from '@common/helpers/xray-config';
1010
import { ERRORS } from '@libs/contracts/constants/errors';
1111

12-
import { StartAllNodesByProfileQueueService } from '@queue/start-all-nodes-by-profile';
13-
import { StopNodeQueueService } from '@queue/stop-node';
12+
import { NodesQueuesService } from '@queue/_nodes';
1413

1514
import { GetConfigProfileByUuidResponseModel } from './models/get-config-profile-by-uuid.response.model';
1615
import { DeleteConfigProfileByUuidResponseModel, GetAllInboundsResponseModel } from './models';
@@ -28,8 +27,7 @@ export class ConfigProfileService {
2827

2928
constructor(
3029
private readonly configProfileRepository: ConfigProfileRepository,
31-
private readonly startAllNodesByProfileQueueService: StartAllNodesByProfileQueueService,
32-
private readonly stopNodeQueueService: StopNodeQueueService,
30+
private readonly nodesQueuesService: NodesQueuesService,
3331
private readonly queryBus: QueryBus,
3432
) {}
3533

@@ -145,7 +143,7 @@ export class ConfigProfileService {
145143
}
146144

147145
for (const node of configProfile.nodes) {
148-
await this.stopNodeQueueService.stopNode({
146+
await this.nodesQueuesService.stopNode({
149147
nodeUuid: node.uuid,
150148
isNeedToBeDeleted: false,
151149
});
@@ -264,7 +262,7 @@ export class ConfigProfileService {
264262
// No need for now
265263
// await this.commandBus.execute(new SyncActiveProfileCommand());
266264

267-
await this.startAllNodesByProfileQueueService.startAllNodesByProfile({
265+
await this.nodesQueuesService.startAllNodesByProfile({
268266
profileUuid: existingConfigProfile.uuid,
269267
emitter: 'updateConfigProfile',
270268
});

src/modules/external-squads/external-squads.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ICommandResponse } from '@common/types/command-response.type';
1010
import { CACHE_KEYS, TSubscriptionTemplateType } from '@libs/contracts/constants';
1111
import { ERRORS } from '@libs/contracts/constants/errors';
1212

13-
import { ExternalSquadActionsQueueService } from '@queue/external-squad-actions';
13+
import { SquadsQueueService } from '@queue/_squads';
1414

1515
import {
1616
DeleteExternalSquadByUuidResponseModel,
@@ -28,7 +28,7 @@ export class ExternalSquadService {
2828

2929
constructor(
3030
private readonly externalSquadRepository: ExternalSquadRepository,
31-
private readonly externalSquadActionsQueueService: ExternalSquadActionsQueueService,
31+
private readonly squadsQueueService: SquadsQueueService,
3232
@Inject(CACHE_MANAGER) private cacheManager: Cache,
3333
) {}
3434

@@ -251,7 +251,7 @@ export class ExternalSquadService {
251251
};
252252
}
253253

254-
await this.externalSquadActionsQueueService.addUsersToExternalSquad({
254+
await this.squadsQueueService.addUsersToExternalSquad({
255255
externalSquadUuid: uuid,
256256
});
257257

@@ -281,7 +281,7 @@ export class ExternalSquadService {
281281
};
282282
}
283283

284-
await this.externalSquadActionsQueueService.removeUsersFromExternalSquad({
284+
await this.squadsQueueService.removeUsersFromExternalSquad({
285285
externalSquadUuid: uuid,
286286
});
287287

src/modules/internal-squads/internal-squad.service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Injectable, Logger } from '@nestjs/common';
66
import { ICommandResponse } from '@common/types/command-response.type';
77
import { ERRORS } from '@libs/contracts/constants/errors';
88

9-
import { StartAllNodesByProfileQueueService } from '@queue/start-all-nodes-by-profile';
10-
import { InternalSquadActionsQueueService } from '@queue/internal-squad-actions';
9+
import { SquadsQueueService } from '@queue/_squads';
10+
import { NodesQueuesService } from '@queue/_nodes';
1111

1212
import { GetInternalSquadByUuidResponseModel } from './models/get-internal-squad-by-uuid.response.model';
1313
import { DeleteInternalSquadResponseModel } from './models/delete-internal-squad-by-uuid.response.model';
@@ -24,8 +24,8 @@ export class InternalSquadService {
2424

2525
constructor(
2626
private readonly internalSquadRepository: InternalSquadRepository,
27-
private readonly startAllNodesByProfileQueueService: StartAllNodesByProfileQueueService,
28-
private readonly internalSquadActionsQueueService: InternalSquadActionsQueueService,
27+
private readonly nodesQueuesService: NodesQueuesService,
28+
private readonly squadsQueueService: SquadsQueueService,
2929
) {}
3030

3131
public async getInternalSquads(): Promise<ICommandResponse<GetInternalSquadsResponseModel>> {
@@ -197,7 +197,7 @@ export class InternalSquadService {
197197

198198
await Promise.all(
199199
affectedConfigProfiles.map((profileUuid) =>
200-
this.startAllNodesByProfileQueueService.startAllNodesByProfile({
200+
this.nodesQueuesService.startAllNodesByProfile({
201201
profileUuid,
202202
emitter: 'updateInternalSquad',
203203
}),
@@ -264,7 +264,7 @@ export class InternalSquadService {
264264
const deleted = await this.internalSquadRepository.deleteByUUID(uuid);
265265

266266
for (const profileUuid of includedProfiles) {
267-
await this.startAllNodesByProfileQueueService.startAllNodesByProfile({
267+
await this.nodesQueuesService.startAllNodesByProfile({
268268
profileUuid,
269269
emitter: 'deleteInternalSquad',
270270
});
@@ -296,7 +296,7 @@ export class InternalSquadService {
296296
};
297297
}
298298

299-
await this.internalSquadActionsQueueService.addUsersToInternalSquad({
299+
await this.squadsQueueService.addUsersToInternalSquad({
300300
internalSquadUuid: uuid,
301301
});
302302

@@ -326,7 +326,7 @@ export class InternalSquadService {
326326
};
327327
}
328328

329-
await this.internalSquadActionsQueueService.removeUsersFromInternalSquad({
329+
await this.squadsQueueService.removeUsersFromInternalSquad({
330330
internalSquadUuid: uuid,
331331
});
332332

0 commit comments

Comments
 (0)