progress indicator added
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
import { rm } from "node:fs/promises";
|
||||
|
||||
type Job = {
|
||||
dir: string;
|
||||
zipPath: string;
|
||||
createdAt: number;
|
||||
};
|
||||
|
||||
const JOB_TTL_MS = 15 * 60 * 1000;
|
||||
const jobs = new Map<string, Job>();
|
||||
|
||||
function sweepExpiredJobs(): void {
|
||||
const cutoff = Date.now() - JOB_TTL_MS;
|
||||
for (const [id, job] of jobs) {
|
||||
if (job.createdAt > cutoff) continue;
|
||||
jobs.delete(id);
|
||||
void rm(job.dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
export function saveJob(dir: string, zipPath: string): string {
|
||||
sweepExpiredJobs();
|
||||
const id = crypto.randomUUID();
|
||||
jobs.set(id, { dir, zipPath, createdAt: Date.now() });
|
||||
return id;
|
||||
}
|
||||
|
||||
export function takeJob(id: string): Job | null {
|
||||
const job = jobs.get(id);
|
||||
if (!job) return null;
|
||||
jobs.delete(id);
|
||||
return job;
|
||||
}
|
||||
Reference in New Issue
Block a user