fase(8): sqlite job queue system

This commit is contained in:
debian
2026-03-05 09:44:06 -05:00
parent f01acfe985
commit 39a5e41f75
17 changed files with 819 additions and 22 deletions

View File

@@ -37,6 +37,11 @@ import { RunFuzzCommand } from './modules/fuzzing/application/commands/RunFuzzCo
import { OnActionExecuted } from './modules/fuzzing/application/event-handlers/OnActionExecuted';
import { InMemoryFuzzSessionRepository } from './modules/fuzzing/infrastructure/repositories/InMemoryFuzzSessionRepository';
// Job queue
import { SQLiteJobQueue } from './jobs/SQLiteJobQueue';
import { createExplorationJobHandler, EXPLORATION_JOB_TYPE } from './jobs/workers/ExplorationWorker';
import { createReportJobHandler, REPORT_JOB_TYPE } from './jobs/workers/ReportWorker';
// API + Realtime
import { createServer } from './api/server';
import { SocketGateway } from './realtime/SocketGateway';
@@ -104,20 +109,29 @@ async function bootstrap(): Promise<void> {
const httpServer = http.createServer(app);
// 11. Socket.io + gateway
// 11. Job queue
const jobQueue = new SQLiteJobQueue(db, logger, config.jobs.pollIntervalMs);
jobQueue.registerHandler(
EXPLORATION_JOB_TYPE,
createExplorationJobHandler({ sessionRepo, eventBus, logger }),
);
jobQueue.registerHandler(REPORT_JOB_TYPE, createReportJobHandler({ logger }));
jobQueue.start();
// 12. Socket.io + gateway
const io = new SocketIOServer(httpServer, {
cors: { origin: config.cors.origin, credentials: true },
});
const gateway = new SocketGateway(io, eventBus, logger);
gateway.start();
// 12. Start listening
// 13. Start listening
await new Promise<void>((resolve) => {
httpServer.listen(config.port, config.host, resolve);
});
logger.info({ port: config.port, host: config.host }, 'ABE server ready');
// 13. Graceful shutdown
// 14. Graceful shutdown
let shuttingDown = false;
async function shutdown(signal: string): Promise<void> {
@@ -132,6 +146,10 @@ async function bootstrap(): Promise<void> {
// Close socket.io
io.close();
// Stop job queue and wait for active jobs
jobQueue.pause();
await jobQueue.waitForActive(30_000);
// Close database
try {
await db.destroy();