refactor(multi-server): add docker cleanup cron

This commit is contained in:
Mauricio Siu
2024-09-21 22:47:19 -06:00
parent 82588f3e16
commit ff482ffe28
3 changed files with 22 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ import { runMariadbBackup } from "./mariadb";
import { runMongoBackup } from "./mongo";
import { runMySqlBackup } from "./mysql";
import { runPostgresBackup } from "./postgres";
import { getAllServers } from "@/server/api/services/server";
export const initCronJobs = async () => {
console.log("Setting up cron jobs....");
@@ -27,6 +28,22 @@ export const initCronJobs = async () => {
});
}
const servers = await getAllServers();
for (const server of servers) {
const { appName, serverId } = server;
if (serverId) {
scheduleJob(serverId, "0 0 * * *", async () => {
console.log(
`SERVER-BACKUP[${new Date().toLocaleString()}] Running Cleanup ${appName}`,
);
await cleanUpUnusedImages(serverId);
await cleanUpDockerBuilder(serverId);
await cleanUpSystemPrune(serverId);
});
}
}
const pgs = await db.query.postgres.findMany({
with: {
backups: {