feat(TRUEREF-0022): complete iteration 0 — worker-thread indexing, parallel jobs, SSE progress
- Move IndexingPipeline.run() into Worker Threads via WorkerPool - Add dedicated embedding worker thread with single model instance - Add stage/stageDetail columns to indexing_jobs schema - Create ProgressBroadcaster for SSE channel management - Add SSE endpoints: GET /api/v1/jobs/:id/stream, GET /api/v1/jobs/stream - Replace UI polling with EventSource on repo detail and admin pages - Add concurrency settings UI and API endpoint - Build worker entries separately via esbuild
This commit is contained in:
52
src/routes/api/v1/jobs/stream/+server.ts
Normal file
52
src/routes/api/v1/jobs/stream/+server.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* GET /api/v1/jobs/stream — stream real-time job progress for all jobs or a specific repository via SSE.
|
||||
*
|
||||
* Query parameters:
|
||||
* repositoryId (optional) — filter to jobs for this repository
|
||||
*/
|
||||
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getBroadcaster } from '$lib/server/pipeline/progress-broadcaster.js';
|
||||
import { handleServiceError } from '$lib/server/utils/validation.js';
|
||||
|
||||
export const GET: RequestHandler = ({ url }) => {
|
||||
try {
|
||||
const broadcaster = getBroadcaster();
|
||||
if (!broadcaster) {
|
||||
return new Response('Service unavailable', { status: 503 });
|
||||
}
|
||||
|
||||
const repositoryId = url.searchParams.get('repositoryId');
|
||||
|
||||
// Get the appropriate stream based on parameters
|
||||
let stream;
|
||||
if (repositoryId) {
|
||||
stream = broadcaster.subscribeRepository(repositoryId);
|
||||
} else {
|
||||
stream = broadcaster.subscribeAll();
|
||||
}
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Connection': 'keep-alive',
|
||||
'X-Accel-Buffering': 'no',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
return handleServiceError(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const OPTIONS: RequestHandler = () => {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user