Skip to content

Commit d26b3c9

Browse files
author
Nevo David
committed
refactor bull mq
1 parent 8ac7c65 commit d26b3c9

33 files changed

+228
-543
lines changed

apps/backend/src/api/api.module.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { PermissionsService } from '@gitroom/backend/services/auth/permissions/p
1111
import { IntegrationsController } from '@gitroom/backend/api/routes/integrations.controller';
1212
import { IntegrationManager } from '@gitroom/nestjs-libraries/integrations/integration.manager';
1313
import { SettingsController } from '@gitroom/backend/api/routes/settings.controller';
14-
import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport/bull-mq.module';
1514
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
1615
import { PostsController } from '@gitroom/backend/api/routes/posts.controller';
1716
import { MediaController } from '@gitroom/backend/api/routes/media.controller';
@@ -47,9 +46,6 @@ const authenticatedController = [
4746
@Module({
4847
imports: [
4948
UploadModule,
50-
BullMqModule.forRoot({
51-
connection: ioRedis,
52-
}),
5349
...(!!process.env.UPLOAD_DIRECTORY &&
5450
!!process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY
5551
? [
@@ -63,7 +59,12 @@ const authenticatedController = [
6359
]
6460
: []),
6561
],
66-
controllers: [StripeController, AuthController, PublicController, ...authenticatedController],
62+
controllers: [
63+
StripeController,
64+
AuthController,
65+
PublicController,
66+
...authenticatedController,
67+
],
6768
providers: [
6869
AuthService,
6970
StripeService,

apps/backend/src/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {DatabaseModule} from "@gitroom/nestjs-libraries/database/prisma/database
44
import {ApiModule} from "@gitroom/backend/api/api.module";
55
import {APP_GUARD} from "@nestjs/core";
66
import {PoliciesGuard} from "@gitroom/backend/services/auth/permissions/permissions.guard";
7+
import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport-new/bull.mq.module';
78

89
@Global()
910
@Module({
10-
imports: [DatabaseModule, ApiModule],
11+
imports: [BullMqModule, DatabaseModule, ApiModule],
1112
controllers: [],
1213
providers: [{
1314
provide: APP_GUARD,

apps/commands/src/command.module.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@ import { Module } from '@nestjs/common';
22
import { CommandModule as ExternalCommandModule } from 'nestjs-command';
33
import { CheckStars } from './tasks/check.stars';
44
import { DatabaseModule } from '@gitroom/nestjs-libraries/database/prisma/database.module';
5-
import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport/bull-mq.module';
6-
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
7-
import {RefreshTokens} from "./tasks/refresh.tokens";
5+
import { RefreshTokens } from './tasks/refresh.tokens';
6+
import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport-new/bull.mq.module';
87

98
@Module({
10-
imports: [
11-
ExternalCommandModule,
12-
DatabaseModule,
13-
BullMqModule.forRoot({
14-
connection: ioRedis,
15-
}),
16-
],
9+
imports: [ExternalCommandModule, DatabaseModule, BullMqModule],
1710
controllers: [],
1811
providers: [CheckStars, RefreshTokens],
1912
get exports() {
Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
1-
import {Command, Positional} from 'nestjs-command';
1+
import { Command, Positional } from 'nestjs-command';
22
import { Injectable } from '@nestjs/common';
3-
import {BullMqClient} from "@gitroom/nestjs-libraries/bull-mq-transport/client/bull-mq.client";
3+
import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client';
44

55
@Injectable()
66
export class CheckStars {
7-
constructor(
8-
private _workerServiceProducer: BullMqClient
9-
) {
10-
}
11-
@Command({
12-
command: 'sync:stars <login>',
13-
describe: 'Sync stars for a login',
7+
constructor(private _workerServiceProducer: BullMqClient) {}
8+
@Command({
9+
command: 'sync:stars <login>',
10+
describe: 'Sync stars for a login',
11+
})
12+
async create(
13+
@Positional({
14+
name: 'login',
15+
describe: 'login {owner}/{repo}',
16+
type: 'string',
1417
})
15-
async create(
16-
@Positional({
17-
name: 'login',
18-
describe: 'login {owner}/{repo}',
19-
type: 'string'
20-
})
21-
login: string,
22-
) {
23-
this._workerServiceProducer.emit('check_stars', {payload: {login}}).subscribe();
24-
return true;
25-
}
18+
login: string
19+
) {
20+
this._workerServiceProducer
21+
.emit('check_stars', { payload: { login } })
22+
.subscribe();
23+
return true;
24+
}
2625

27-
@Command({
28-
command: 'sync:all_stars <login>',
29-
describe: 'Sync all stars for a login',
26+
@Command({
27+
command: 'sync:all_stars <login>',
28+
describe: 'Sync all stars for a login',
29+
})
30+
async syncAllStars(
31+
@Positional({
32+
name: 'login',
33+
describe: 'login {owner}/{repo}',
34+
type: 'string',
3035
})
31-
async syncAllStars(
32-
@Positional({
33-
name: 'login',
34-
describe: 'login {owner}/{repo}',
35-
type: 'string'
36-
})
37-
login: string,
38-
) {
39-
this._workerServiceProducer.emit('sync_all_stars', {payload: {login}}).subscribe();
40-
return true;
41-
}
36+
login: string
37+
) {
38+
this._workerServiceProducer
39+
.emit('sync_all_stars', { payload: { login } })
40+
.subscribe();
41+
return true;
42+
}
4243

43-
@Command({
44-
command: 'sync:trending',
45-
describe: 'Sync trending',
46-
})
47-
async syncTrending() {
48-
this._workerServiceProducer.emit('sync_trending', {}).subscribe();
49-
return true;
50-
}
51-
}
44+
@Command({
45+
command: 'sync:trending',
46+
describe: 'Sync trending',
47+
})
48+
async syncTrending() {
49+
this._workerServiceProducer.emit('sync_trending', {}).subscribe();
50+
return true;
51+
}
52+
}

apps/cron/src/cron.module.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@ import { Module } from '@nestjs/common';
22
import { ScheduleModule } from '@nestjs/schedule';
33
import { CheckStars } from '@gitroom/cron/tasks/check.stars';
44
import { DatabaseModule } from '@gitroom/nestjs-libraries/database/prisma/database.module';
5-
import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport/bull-mq.module';
6-
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
75
import { SyncTrending } from '@gitroom/cron/tasks/sync.trending';
6+
import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport-new/bull.mq.module';
87

98
@Module({
10-
imports: [
11-
DatabaseModule,
12-
ScheduleModule.forRoot(),
13-
BullMqModule.forRoot({
14-
connection: ioRedis,
15-
}),
16-
],
9+
imports: [DatabaseModule, ScheduleModule.forRoot(), BullMqModule],
1710
controllers: [],
1811
providers: [CheckStars, SyncTrending],
1912
})

apps/cron/src/tasks/check.stars.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@nestjs/common';
22
import { Cron } from '@nestjs/schedule';
33
import { StarsService } from '@gitroom/nestjs-libraries/database/prisma/stars/stars.service';
4-
import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport/client/bull-mq.client';
4+
import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client';
55

66
@Injectable()
77
export class CheckStars {

apps/cron/src/tasks/sync.trending.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { Cron } from '@nestjs/schedule';
3-
import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport/client/bull-mq.client';
3+
import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client';
44

55
@Injectable()
66
export class SyncTrending {

apps/workers/src/app/app.module.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { Module } from '@nestjs/common';
22

33
import { StarsController } from './stars.controller';
44
import {DatabaseModule} from "@gitroom/nestjs-libraries/database/prisma/database.module";
5-
import {BullMqModule} from "@gitroom/nestjs-libraries/bull-mq-transport/bull-mq.module";
6-
import {ioRedis} from "@gitroom/nestjs-libraries/redis/redis.service";
75
import {TrendingService} from "@gitroom/nestjs-libraries/services/trending.service";
86
import {PostsController} from "@gitroom/workers/app/posts.controller";
7+
import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport-new/bull.mq.module';
98

109
@Module({
11-
imports: [DatabaseModule, BullMqModule.forRoot({
12-
connection: ioRedis
13-
})],
10+
imports: [DatabaseModule, BullMqModule],
1411
controllers: [StarsController, PostsController],
1512
providers: [TrendingService],
1613
})

apps/workers/src/app/posts.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/po
66
export class PostsController {
77
constructor(private _postsService: PostsService) {}
88
@EventPattern('post', Transport.REDIS)
9-
async checkStars(data: { id: string }) {
9+
async post(data: { id: string }) {
10+
console.log('proceccsing', data);
1011
return this._postsService.post(data.id);
1112
}
1213

1314
@EventPattern('submit', Transport.REDIS)
14-
async submitOrderItemForPayout(data: { id: string, releaseURL: string }) {
15+
async payout(data: { id: string, releaseURL: string }) {
1516
return this._postsService.payout(data.id, data.releaseURL);
1617
}
1718
}

apps/workers/src/main.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import {NestFactory} from '@nestjs/core';
22

33
import {AppModule} from './app/app.module';
44
import {MicroserviceOptions} from '@nestjs/microservices';
5-
import {BullMqServer} from "@gitroom/nestjs-libraries/bull-mq-transport/server/bull-mq.server";
5+
import { BullMqServer } from '@gitroom/nestjs-libraries/bull-mq-transport-new/strategy';
66

77
async function bootstrap() {
8-
const load = await NestFactory.create(AppModule);
9-
const strategy = load.get(BullMqServer);
10-
118
// some comment again
129
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
13-
strategy,
10+
strategy: new BullMqServer()
1411
});
1512

1613
await app.listen();

0 commit comments

Comments
 (0)