-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3667 - Bull Scheduler Increments the Next Scheduled Job When Manuall…
…y Promoted (#3957) Updated Bull Board-related packages to take advantage of the feature present in the newer version that allows a new job to be added (same as duplicate), allowing the schedulers to be executed without affecting their current time to be executed again. _Notes:_ 1. during the local tests, when a delayed job was deleted and the `queue-consumers` restarted, the delayed job was restored. 2. this PR is intended to be part of the upcoming release. The research for the ticket will continue. ## Using the add/duplicate option While creating the new job the properties can be edited, for instance, the corn expression can be edited to create a new time to execute the scheduler. _Please note that `timestamp` and `prevMillis` should be removed. These properties are generated once the job is created. As mentioned in the source code, `timestamp` is the "Timestamp when the job was created." and `prevMillis` is a "Internal property used by repeatable jobs."_ ![image](https://github.com/user-attachments/assets/05245952-5bda-48db-a3b6-61e3a2317669) ```json { "repeat": { "count": 1, "key": "__default__::::0 7 * * *", "cron": "0 7 * * *" }, "jobId": "repeat:2c2720c5e8b4e9ce99993becec27a0ff:1731999600000", "delay": 42485905, "timestamp": 1731957114095, "prevMillis": 1731999600000, "attempts": 3, "backoff": { "type": "fixed", "delay": 180000 } } ``` ## Refactor - Refactored the code to move the Bull Board configuration to the Nestjs modules instead of doing it on the main.ts. The refactored code is equivalent to the one previously on the `main.ts`. - Updated icons and labels to make the dashboard look more like part of the SIMS. The way it was done was by targeting less effort. In case it causes some noise during the PR review the code will be removed.
- Loading branch information
1 parent
06eb979
commit 7b8df04
Showing
11 changed files
with
242 additions
and
62 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...ages/backend/apps/queue-consumers/src/bull-board/bull-board-queues-registration.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Inject, LoggerService, Module, OnModuleInit } from "@nestjs/common"; | ||
import { ModuleRef } from "@nestjs/core"; | ||
import { BULL_BOARD_INSTANCE, BullBoardInstance } from "@bull-board/nestjs"; | ||
import { QueueService } from "@sims/services/queue/queue.service"; | ||
import { InjectLogger } from "@sims/utilities/logger"; | ||
import { getQueueToken } from "@nestjs/bull"; | ||
import { Queue } from "bull"; | ||
import { BullAdapter } from "@bull-board/api/bullAdapter"; | ||
|
||
@Module({}) | ||
export class BullBoardQueuesRegistrationModule implements OnModuleInit { | ||
constructor( | ||
private readonly moduleRef: ModuleRef, | ||
private readonly queueService: QueueService, | ||
@Inject(BULL_BOARD_INSTANCE) | ||
private readonly board: BullBoardInstance, | ||
) {} | ||
|
||
/** | ||
* Adds all queues to the bull board during application initialization | ||
* checking if the queue is active and if it is a scheduler. | ||
*/ | ||
async onModuleInit(): Promise<void> { | ||
const queues = await this.queueService.queueConfigurationModel(); | ||
queues.forEach((queue) => { | ||
if (!queue.isActive && queue.isScheduler) { | ||
this.logger.log(`Queue service '${queue.name}' is inactive.`); | ||
return; | ||
} | ||
const queueProvider = this.moduleRef.get<Queue>( | ||
getQueueToken(queue.name), | ||
{ | ||
strict: false, | ||
}, | ||
); | ||
const queueAdapter = new BullAdapter(queueProvider, { | ||
readOnlyMode: queue.dashboardReadonly, | ||
}); | ||
this.board.addQueue(queueAdapter); | ||
}); | ||
} | ||
|
||
@InjectLogger() | ||
logger: LoggerService; | ||
} |
58 changes: 58 additions & 0 deletions
58
sources/packages/backend/apps/queue-consumers/src/bull-board/bull-board-queues.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { BullBoardModule, BullBoardModuleOptions } from "@bull-board/nestjs"; | ||
import { ConfigModule, ConfigService } from "@sims/utilities/config"; | ||
import * as basicAuth from "express-basic-auth"; | ||
import { ExpressAdapter } from "@bull-board/express"; | ||
import { BULL_BOARD_ROUTE } from "../constants"; | ||
import { BullBoardQueuesRegistrationModule } from "./bull-board-queues-registration.module"; | ||
|
||
/** | ||
* Bull board related modules to allow the dashboard to be registered. | ||
*/ | ||
@Module({ | ||
imports: [ | ||
BullBoardModule.forRootAsync({ | ||
imports: [ConfigModule], | ||
useFactory: bullBoardModuleFactory, | ||
inject: [ConfigService], | ||
}), | ||
BullBoardQueuesRegistrationModule, | ||
], | ||
exports: [BullBoardModule, BullBoardQueuesRegistrationModule], | ||
}) | ||
export class BullBoardQueuesModule {} | ||
|
||
/** | ||
* Builds the Bull Board module options to register the dashboard in a dynamic way. | ||
* @param configService service with the configuration of the application. | ||
* @returns Bull Board module options with the dashboard route, | ||
* authentication middleware and the board options. | ||
*/ | ||
async function bullBoardModuleFactory( | ||
configService: ConfigService, | ||
): Promise<BullBoardModuleOptions> { | ||
const queueDashboardUsers = {}; | ||
queueDashboardUsers[configService.queueDashboardCredential.userName] = | ||
configService.queueDashboardCredential.password; | ||
const authMiddleware = basicAuth({ | ||
users: queueDashboardUsers, | ||
challenge: true, | ||
}); | ||
return { | ||
route: BULL_BOARD_ROUTE, | ||
adapter: ExpressAdapter, | ||
middleware: authMiddleware, | ||
boardOptions: { | ||
uiConfig: { | ||
boardTitle: "SIMS-Queues", | ||
boardLogo: { | ||
path: "https://sims.studentaidbc.ca/favicon-32x32.png", | ||
}, | ||
favIcon: { | ||
default: "https://sims.studentaidbc.ca/favicon-16x16.png", | ||
alternative: "https://sims.studentaidbc.ca/favicon-32x32.png", | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
2 changes: 2 additions & 0 deletions
2
sources/packages/backend/apps/queue-consumers/src/constants/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./error-code.constants"; | ||
export * from "./system-configurations.constants"; |
4 changes: 4 additions & 0 deletions
4
...es/packages/backend/apps/queue-consumers/src/constants/system-configurations.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Bull Dashboard route. | ||
*/ | ||
export const BULL_BOARD_ROUTE = "admin/queues"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
sources/packages/backend/libs/test-utils/src/mocks/bull-board-queues-module-mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Global, Module } from "@nestjs/common"; | ||
|
||
/** | ||
* Mock to entirely replace the Bull Board queues module | ||
* that are not part of the E2E tests. | ||
*/ | ||
@Global() | ||
@Module({}) | ||
export class BullBoardQueuesModuleMock {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters