mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 02:42:45 +00:00
feat: handle repository download and remove using a job queue
This commit is contained in:
50
src/queue.ts
Normal file
50
src/queue.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import * as Queue from "bull";
|
||||
import config from "../config";
|
||||
import { getRepository } from "./database/database";
|
||||
import Repository from "./Repository";
|
||||
|
||||
export const removeQueue = new Queue<Repository>("repository removal", {
|
||||
redis: {
|
||||
host: config.REDIS_HOSTNAME,
|
||||
port: config.REDIS_PORT,
|
||||
},
|
||||
});
|
||||
removeQueue.on("completed", async (job) => {
|
||||
await job.remove();
|
||||
});
|
||||
export const downloadQueue = new Queue<Repository>("repository download", {
|
||||
redis: {
|
||||
host: config.REDIS_HOSTNAME,
|
||||
port: config.REDIS_PORT,
|
||||
},
|
||||
});
|
||||
downloadQueue.on("completed", async (job) => {
|
||||
await job.remove();
|
||||
});
|
||||
|
||||
removeQueue.process(5, async (job) => {
|
||||
console.log(`${job.data.repoId} is going to be removed`);
|
||||
try {
|
||||
const repo = await getRepository(job.data.repoId);
|
||||
await repo.remove();
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
} finally {
|
||||
console.log(`${job.data.repoId} is removed`);
|
||||
}
|
||||
});
|
||||
|
||||
downloadQueue.process(2, async (job) => {
|
||||
console.log(`${job.data.repoId} is going to be downloaded`);
|
||||
try {
|
||||
const repo = await getRepository(job.data.repoId);
|
||||
job.progress("get_repo");
|
||||
await repo.remove();
|
||||
job.progress("get_remove");
|
||||
await repo.anonymize();
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
} finally {
|
||||
console.log(`${job.data.repoId} is downloaded`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user