fase(19): scheduling module refactor
This commit is contained in:
23
src/main.ts
23
src/main.ts
@@ -65,6 +65,14 @@ import { OnFindingCreated } from './modules/integrations/application/event-handl
|
||||
import { RSALicenseValidator } from './modules/licensing/infrastructure/validators/RSALicenseValidator';
|
||||
import { LicenseService } from './modules/licensing/application/LicenseService';
|
||||
|
||||
// Scheduling module
|
||||
import { KyselyScheduleRepository } from './modules/scheduling/infrastructure/repositories/KyselyScheduleRepository';
|
||||
import { CreateScheduleCommand } from './modules/scheduling/application/commands/CreateScheduleCommand';
|
||||
import { ToggleScheduleCommand } from './modules/scheduling/application/commands/ToggleScheduleCommand';
|
||||
import { DeleteScheduleCommand } from './modules/scheduling/application/commands/DeleteScheduleCommand';
|
||||
import { ListSchedulesQuery } from './modules/scheduling/application/queries/ListSchedulesQuery';
|
||||
import { SchedulingService } from './modules/scheduling/application/SchedulingService';
|
||||
|
||||
// Job queue
|
||||
import { SQLiteJobQueue } from './jobs/SQLiteJobQueue';
|
||||
import { createExplorationJobHandler, EXPLORATION_JOB_TYPE } from './jobs/workers/ExplorationWorker';
|
||||
@@ -147,7 +155,7 @@ async function bootstrap(): Promise<void> {
|
||||
const licenseValidator = new RSALicenseValidator();
|
||||
const licenseService = new LicenseService(licenseValidator);
|
||||
|
||||
// 11c. Integrations
|
||||
// 11c. Integrations (moved from 11d)
|
||||
const integrationRepo = new KyselyIntegrationRepository(db);
|
||||
const webhookRepo = new KyselyWebhookEndpointRepository(db);
|
||||
const webhookDispatcher = new WebhookDispatcher(webhookRepo, logger);
|
||||
@@ -163,6 +171,15 @@ async function bootstrap(): Promise<void> {
|
||||
jobQueue.registerHandler(REPORT_JOB_TYPE, createReportJobHandler({ logger, reportRepository: reportRepo, findingRepository: findingRepo }));
|
||||
jobQueue.start();
|
||||
|
||||
// 12b. Scheduling module (after job queue, since it enqueues jobs)
|
||||
const scheduleRepo = new KyselyScheduleRepository(db);
|
||||
const createSchedule = new CreateScheduleCommand(scheduleRepo, eventBus);
|
||||
const toggleSchedule = new ToggleScheduleCommand(scheduleRepo, eventBus);
|
||||
const deleteSchedule = new DeleteScheduleCommand(scheduleRepo, eventBus);
|
||||
const listSchedules = new ListSchedulesQuery(scheduleRepo);
|
||||
const schedulingService = new SchedulingService(scheduleRepo, jobQueue, eventBus, logger);
|
||||
await schedulingService.start();
|
||||
|
||||
// 13. HTTP server
|
||||
const app = createServer({
|
||||
config,
|
||||
@@ -173,6 +190,7 @@ async function bootstrap(): Promise<void> {
|
||||
fuzzingDeps: { runFuzz, repository: fuzzRepo },
|
||||
reportingDeps: { generateReport, reportRepository: reportRepo, jobQueue },
|
||||
integrationsDeps: { integrationRepo, webhookRepo },
|
||||
schedulingDeps: { createSchedule, toggleSchedule, deleteSchedule, listSchedules, schedulingService, scheduleRepo },
|
||||
licenseService,
|
||||
authDeps: {
|
||||
registerCommand,
|
||||
@@ -218,6 +236,9 @@ async function bootstrap(): Promise<void> {
|
||||
// Close socket.io
|
||||
io.close();
|
||||
|
||||
// Stop scheduling service
|
||||
schedulingService.stop();
|
||||
|
||||
// Stop job queue and wait for active jobs
|
||||
jobQueue.pause();
|
||||
await jobQueue.waitForActive(30_000);
|
||||
|
||||
Reference in New Issue
Block a user