import { createBullBoard } from '@bull-board/api'; import { BullMQAdapter } from '@bull-board/api/bullMQAdapter'; import { ExpressAdapter } from '@bull-board/express'; import { type JobsOptions } from 'bullmq'; import express, { type Request, type Response } from 'express'; import { generalQueue } from './queues/generalQueue.ts'; import { gpuQueue } from './queues/gpuQueue.ts'; import { highPriorityQueue } from './queues/highPriorityQueue.ts'; import env from '../.config/env.ts'; import { version } from '../package.json'; const run = async () => { const app = express(); const serverAdapter = new ExpressAdapter(); serverAdapter.setBasePath('/ui'); createBullBoard({ queues: [ new BullMQAdapter(highPriorityQueue), new BullMQAdapter(generalQueue), new BullMQAdapter(gpuQueue), ], serverAdapter, }); console.log('importing workers'); if (process.env.NODE_ENV === 'development') { await import('./workers/highPriorityWorker.ts'); await import('./workers/generalWorker.ts'); await import('./workers/gpuWorker.ts'); } else { // @todo I separated these so that they can be ran on multiple machines. // @todo we should activate these based on environment variable feature flags, not NODE_ENV await import('./workers/highPriorityWorker.ts'); await import('./workers/generalWorker.ts'); // await import('./workers/gpuWorker.ts'); // @todo implement } app.get('/', (req: Request, res: Response) => { res.send(`

FP Worker version ${version}.

Actions

If you find yourself clicking one of these links a lot, consider automating it by putting the job in a queue on a every or pattern timer.

`) }) app.use('/ui', serverAdapter.getRouter()); app.get('/task', async (req: Request, res: Response) => { const name = req.query.name as string; const vodId = req.query.vodId as string; // console.log('vodId', vodId, 'name', name); // console.log(JSON.stringify(req.query, null, 2)) const data = { vodId }; switch (name) { case '': throw new Error('job name was missing'); case 'scheduleVodProcessing': await gpuQueue.add(name, data); break; default: await highPriorityQueue.add(name, data); break; } res.json({ ok: true }); }); app.listen(env.WORKER_PORT, () => { console.log(`Bull Dashboard running at http://localhost:${env.WORKER_PORT}/ui`); console.log(`Actions Menu: http://localhost:${env.WORKER_PORT}`); }); }; run().catch((e) => console.error(e));