Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate BullBoard and optimize queue registration #44

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ S3_BUCKET="0lfyi-v7"
S3_STORAGE_CLASS="STANDARD"
S3_USE_SSL=false

NODE_ENV=

CLICKHOUSE_HOST="127.0.0.1"
CLICKHOUSE_USERNAME="default"
CLICKHOUSE_PASSWORD=""
Expand Down
151 changes: 146 additions & 5 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"@apollo/server": "^4.10.4",
"@aptos-labs/ts-sdk": "^1.16.0",
"@aws-sdk/client-s3": "^3.583.0",
"@bull-board/api": "^5.19.2",
"@bull-board/express": "^5.19.2",
"@bull-board/nestjs": "^5.19.2",
"@clickhouse/client": "^1.0.2",
"@nestjs/apollo": "^12.1.0",
"@nestjs/bullmq": "^10.1.1",
Expand Down
1 change: 0 additions & 1 deletion api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import { MultiSigModule } from "../multi-sig/multi-sig.module.js";
StatsModule,
WalletSubscriptionModule,
OlSwapModule,
NodeWatcherModule,
minaxolone marked this conversation as resolved.
Show resolved Hide resolved
MultiSigModule,
],
controllers: [],
Expand Down
56 changes: 56 additions & 0 deletions api/src/bullboard/bullboard.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Injectable } from '@nestjs/common';
import { Queue } from 'bullmq';
import { createBullBoard } from '@bull-board/api';
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter.js';
import { ExpressAdapter } from '@bull-board/express';
import { redisClient } from "../redis/redis.service.js";

@Injectable()
export class BullBoardService {

private readonly serverAdapter: ExpressAdapter;
private readonly queueNames: string[] = [
"ol-clickhouse-ingestor",
"ol-parquet-producer",
"ol-version-batch",
"ol-version",
"expired-transactions",
"ol-swap",
"node-watcher",
"wallet-subscription",
"stats"
];

constructor() {
this.serverAdapter = new ExpressAdapter();
}

onModuleInit() {
if (process.env.NODE_ENV !== 'production') {
this.setupBullBoard(
this.queueNames.map(name => ({
name,
connection: redisClient,
}))
);
}
}

setupBullBoard(queueConfigs: { name: string; connection: any }[]) {
const queues: Queue<any, any, string>[] = queueConfigs.map(
(config) => new Queue(config.name, { connection: config.connection })
);

createBullBoard({
queues: queues.map((queue) => new BullMQAdapter(queue)),
serverAdapter: this.serverAdapter,
});

this.serverAdapter.setBasePath('/ui');
}

getServerAdapter() {
return this.serverAdapter;
}

}
6 changes: 6 additions & 0 deletions api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NestFactory } from "@nestjs/core";
import { NestExpressApplication } from "@nestjs/platform-express";
import { AppModule } from "./app/app.module.js";
import getConfig from "./config/config.js";
import { BullBoardService } from './bullboard/bullboard.service.js';

async function bootstrap() {
const config = getConfig();
Expand All @@ -15,6 +16,11 @@ async function bootstrap() {
app.set("trust proxy", 1);
app.enableCors();

if (process.env.NODE_ENV !== 'production') {
const bullBoardService = app.get(BullBoardService);
app.use('/ui', bullBoardService.getServerAdapter().getRouter());
}

await app.listen(config.port);
}
bootstrap();
Loading