const crypto = require('crypto'); const jobs = new Map(); function createJob(total) { const id = crypto.randomUUID(); jobs.set(id, { id, status: 'processing', total, processed: 0, errors: 0, download: null, startedAt: new Date() }); return id; } function incrementProcessed(id) { const job = jobs.get(id); if (job) job.processed++; } function incrementErrors(id) { const job = jobs.get(id); if (job) job.errors++; } function finishJob(id, download) { const job = jobs.get(id); if (job) { job.status = 'done'; job.download = download; job.finishedAt = new Date(); } } function failJob(id, error) { const job = jobs.get(id); if (job) { job.status = 'error'; job.error = error; } } function getJob(id) { return jobs.get(id); } module.exports = { createJob, incrementProcessed, incrementErrors, finishJob, failJob, getJob };