Skip to content

Commit

Permalink
Add stub for recurring system status check job
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Oct 3, 2024
1 parent a7221de commit 34a5f71
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
8 changes: 7 additions & 1 deletion source/SIL.AppBuilder.Portal/common/BullJobTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export enum ScriptoriaJobType {
EmailReviewers = 'EmailReviewers',
PublishProduct = 'PublishProduct',
CheckBuildProduct = 'CheckBuildProduct',
CheckPublishProduct = 'CheckPublishProduct'
CheckPublishProduct = 'CheckPublishProduct',
CheckSystemStatuses = 'CheckSystemStatuses'
}

export interface TestJob {
Expand Down Expand Up @@ -63,6 +64,10 @@ export interface CheckPublishProductJob {
releaseId: number;
}

export interface CheckSystemStatusesJob {
type: ScriptoriaJobType.CheckSystemStatuses;
}

export type ScriptoriaJob = JobTypeMap[keyof JobTypeMap];

export type JobTypeMap = {
Expand All @@ -74,5 +79,6 @@ export type JobTypeMap = {
[ScriptoriaJobType.PublishProduct]: PublishProductJob;
[ScriptoriaJobType.CheckBuildProduct]: CheckBuildProductJob;
[ScriptoriaJobType.CheckPublishProduct]: CheckPublishProductJob;
[ScriptoriaJobType.CheckSystemStatuses]: CheckSystemStatusesJob;
// Add more mappings here as needed
};
4 changes: 4 additions & 0 deletions source/SIL.AppBuilder.Portal/node-server/BullWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class ScriptoriaWorker extends BullWorker<BullMQ.ScriptoriaJob, number> {
return new Executor.CheckPublishProduct().execute(
job as Job<BullMQ.CheckPublishProductJob, number, string>
);
case BullMQ.ScriptoriaJobType.CheckSystemStatuses:
return new Executor.CheckSystemStatuses().execute(
job as Job<BullMQ.CheckSystemStatusesJob, number, string>
);
}
}
}
15 changes: 14 additions & 1 deletion source/SIL.AppBuilder.Portal/node-server/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ process.env.NODE_ENV = 'development';

const app = express();

import { scriptoriaQueue } from 'sil.appbuilder.portal.common';
import { BullMQ, scriptoriaQueue } from 'sil.appbuilder.portal.common';
const serverAdapter = new ExpressAdapter();
serverAdapter.setBasePath('/');
createBullBoard({
Expand All @@ -18,4 +18,17 @@ createBullBoard({
app.use(serverAdapter.getRouter());
app.listen(3000, () => console.log('Dev server started'));

// Recurring job to check the availability of BuildEngine
scriptoriaQueue.add(
'Check System Statuses (Recurring)',
{
type: BullMQ.ScriptoriaJobType.CheckSystemStatuses
},
{
repeat: {
pattern: '*/5 * * * *' // every 5 minutes
}
}
);

new ScriptoriaWorker();
15 changes: 14 additions & 1 deletion source/SIL.AppBuilder.Portal/node-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ app.get('/healthcheck', (req, res) => {
});

// BullMQ variables
import { scriptoriaQueue } from 'sil.appbuilder.portal.common';
import { BullMQ, scriptoriaQueue } from 'sil.appbuilder.portal.common';
// Running on svelte process right now. Consider putting on new thread
// Fine like this if majority of job time is waiting for network requests
// If there is much processing it should be moved to another thread
Expand All @@ -96,3 +96,16 @@ const handler = await import('./build/handler.js');
app.use(handler.handler);

app.listen(3000, () => console.log('Server started!'));

// Recurring job to check the availability of BuildEngine
scriptoriaQueue.add(
'Check System Statuses (Recurring)',
{
type: BullMQ.ScriptoriaJobType.CheckSystemStatuses
},
{
repeat: {
pattern: '*/5 * * * *' // every 5 minutes
}
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export {
CheckBuildProduct,
CheckPublishProduct
} from './product.js';
export { CheckSystemStatuses } from './systemStatus.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BullMQ, prisma, DatabaseWrites } from 'sil.appbuilder.portal.common';
import { Job } from 'bullmq';
import { ScriptoriaJobExecutor } from './base.js';

export class CheckSystemStatuses extends ScriptoriaJobExecutor<BullMQ.ScriptoriaJobType.CheckSystemStatuses> {
async execute(job: Job<BullMQ.CheckSystemStatusesJob, number, string>): Promise<number> {
// TODO: Do I use the `SystemStatus` table? Why does this table even exist? It mostly duplicates data from `Organizations` but is completely disconnected from `Organizations`. Can these be consolidated?
const systems = await prisma.systemStatuses.findMany();
job.updateProgress(10);
//const timestamp = new Date();
systems.forEach((s, i) => {
// TODO: Not doing anything here until above TODO is resolved
job.updateProgress(10 + (i+1) * 80 / systems.length);
});
//await prisma.$transaction(systems.map());
job.updateProgress(100);
return systems.length;
}
}

0 comments on commit 34a5f71

Please sign in to comment.