Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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=local
Comment thread
minaxolone marked this conversation as resolved.
Outdated

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
33 changes: 33 additions & 0 deletions api/src/bullboard/bullboard.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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';

@Injectable()
export class BullBoardService {

private readonly serverAdapter: ExpressAdapter;

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

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;
}

}
8 changes: 8 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,13 @@ async function bootstrap() {
app.set("trust proxy", 1);
app.enableCors();

const isProduction = process.env.NODE_ENV === 'production';

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

await app.listen(config.port);
}
bootstrap();
58 changes: 32 additions & 26 deletions api/src/ol/ol.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { TransactionsService } from "./transactions/TransactionsService.js";
import { Transaction } from "./transactions/Transaction.js";
import { OnChainTransactionsRepository } from "./transactions/OnChainTransactionsRepository.js";
import { ExpiredTransactionsProcessor } from "./transactions/ExpiredTransactionsProcessor.js";
import { BullBoardService } from '../bullboard/bullboard.service.js';

const roles = process.env.ROLES!.split(",");

Expand All @@ -65,6 +66,16 @@ for (const role of roles) {
}
}

// Centralize queue definitions in an array for better reusability
const queues = [
{ name: "ol-clickhouse-ingestor", connection: redisClient},
Comment thread
minaxolone marked this conversation as resolved.
Outdated
{ name: "ol-parquet-producer", connection: redisClient },
{ name: "ol-version-batch", connection: redisClient },
{ name: "ol-version", connection: redisClient },
{ name: "expired-transactions", connection: redisClient },
];


@Module({
imports: [
S3Module,
Expand All @@ -74,30 +85,13 @@ for (const role of roles) {
OlDbModule,
WalletSubscriptionModule,

BullModule.registerQueue({
name: "ol-clickhouse-ingestor",
connection: redisClient,
}),

BullModule.registerQueue({
name: "ol-parquet-producer",
connection: redisClient,
}),

BullModule.registerQueue({
name: "ol-version-batch",
connection: redisClient,
}),

BullModule.registerQueue({
name: "ol-version",
connection: redisClient,
}),

BullModule.registerQueue({
name: "expired-transactions",
connection: redisClient,
}),
// Register queues using a loop to simplify and maintain consistency
BullModule.registerQueue(
...queues.map(queue => ({
name: queue.name,
connection: queue.connection,
}))
),
],
providers: [
UserTransactionsResolver,
Expand All @@ -119,6 +113,8 @@ for (const role of roles) {
MovementsService,
TransformerService,

BullBoardService,

// Transactions
TransactionResolver,
TransactionsResolver,
Expand Down Expand Up @@ -147,6 +143,16 @@ for (const role of roles) {
...workers,
],
controllers: [OlController],
exports: [OlService, TransformerService, Types.ICommunityWalletsService],
exports: [OlService, TransformerService, Types.ICommunityWalletsService, BullBoardService],
})
export class OlModule {}
export class OlModule {
isProduction = process.env.NODE_ENV === 'production';

constructor(private readonly bullBoardService: BullBoardService) {
if (!this.isProduction) {
// Setup BullBoard for the queues in local development environment
// Utilize the same queue array to ensure consistency
this.bullBoardService.setupBullBoard(queues);
Comment thread
saki-osive marked this conversation as resolved.
Outdated
}
}
}