refactor(dokploy): prevent start worker when is cloud

This commit is contained in:
Mauricio Siu
2024-10-25 16:56:32 -06:00
parent 182f908c31
commit 421c93795b
11 changed files with 61 additions and 84 deletions

View File

@@ -1,8 +1,6 @@
import { type ConnectionOptions, Queue } from "bullmq";
import { Queue } from "bullmq";
import { redisConfig } from "./redis-connection";
export const redisConfig: ConnectionOptions = {
host: process.env.NODE_ENV === "production" ? "dokploy-redis" : "127.0.0.1",
};
const myQueue = new Queue("deployments", {
connection: redisConfig,
});
@@ -21,4 +19,26 @@ myQueue.on("error", (error) => {
}
});
export const cleanQueuesByApplication = async (applicationId: string) => {
const jobs = await myQueue.getJobs(["waiting", "delayed"]);
for (const job of jobs) {
if (job?.data?.applicationId === applicationId) {
await job.remove();
console.log(`Removed job ${job.id} for application ${applicationId}`);
}
}
};
export const cleanQueuesByCompose = async (composeId: string) => {
const jobs = await myQueue.getJobs(["waiting", "delayed"]);
for (const job of jobs) {
if (job?.data?.composeId === composeId) {
await job.remove();
console.log(`Removed job ${job.id} for compose ${composeId}`);
}
}
};
export { myQueue };