feat: use differnt processes to handle the queue

This commit is contained in:
tdurieux
2021-09-12 00:05:05 +02:00
parent 07750f7a64
commit bafa0b325b
3 changed files with 62 additions and 43 deletions

View File

@@ -0,0 +1,28 @@
import AnonymousError from "../AnonymousError";
import { connect, getRepository } from "../database/database";
export default async function process(job) {
try {
await connect();
console.log(`${job.data.repoId} is going to be removed`);
const repo = await getRepository(job.data.repoId);
try {
await repo.remove();
} catch (error) {
await repo.updateStatus("error", error.message);
throw error;
}
} catch (error) {
if (error instanceof AnonymousError) {
console.error(
"[ERROR]",
error.toString(),
error.stack.split("\n")[1].trim()
);
} else {
console.error(error);
}
} finally {
console.log(`${job.data.repoId} is removed`);
}
}