feat: import job runner in-memory
- Añade ImportRunner en memoria con concurrencia configurable - Tests TDD para enqueue, concurrencia y comportamiento tras stop - Actualiza /api/import/scan para encolar jobs y registrar errores - Ajusta tsconfig.json para incluir tests en comprobaciones de tipo
This commit is contained in:
25
backend/src/routes/import.ts
Normal file
25
backend/src/routes/import.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { FastifyInstance } from 'fastify';
|
||||
import { runner } from '../jobs/importRunner';
|
||||
|
||||
export default async function importRoutes(app: FastifyInstance) {
|
||||
app.post('/import/scan', async (request, reply) => {
|
||||
const body = request.body as any;
|
||||
|
||||
// Encolar el job en background (placeholder)
|
||||
setImmediate(() => {
|
||||
// placeholder task: no persistencia, trabajo ligero en background
|
||||
runner
|
||||
.enqueue(async () => {
|
||||
// usar body en caso necesario; aquí sólo un placeholder
|
||||
void body;
|
||||
return true;
|
||||
})
|
||||
.catch((err) => {
|
||||
app.log.warn({ err }, 'Background import task failed');
|
||||
});
|
||||
});
|
||||
|
||||
// Responder inmediatamente
|
||||
reply.code(202).send({ status: 'queued' });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user