refactor: add authorization

This commit is contained in:
Mauricio Siu
2024-10-06 01:37:39 -06:00
parent 7cfbea3f60
commit 3cf27a068a
10 changed files with 191 additions and 33 deletions

View File

@@ -1,4 +1,4 @@
import { Queue } from "bullmq";
import { Queue, type RepeatableJob } from "bullmq";
import { logger } from "./logger";
import type { QueueJob } from "./schema";
@@ -52,4 +52,24 @@ export const removeJob = async (data: QueueJob) => {
});
return result;
}
return false;
};
export const getJobRepeatable = async (
data: QueueJob,
): Promise<RepeatableJob | null> => {
const repeatableJobs = await jobQueue.getRepeatableJobs();
if (data.type === "backup") {
const { backupId } = data;
const job = repeatableJobs.find((j) => j.name === backupId);
return job ? job : null;
}
if (data.type === "server") {
const { serverId } = data;
const job = repeatableJobs.find((j) => j.name === `${serverId}-cleanup`);
return job ? job : null;
}
return null;
};