-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resolve #56 #61
base: main
Are you sure you want to change the base?
resolve #56 #61
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
.vscode | ||
node_modules | ||
dumps/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CronJob } from "cron"; | ||
import { dumpDatabase, removeOldDumps } from "@/utils/database"; | ||
|
||
|
||
export const dumpDatabaseJob = CronJob.from({ | ||
start: false, | ||
cronTime: "0 0 4 * * *", | ||
onComplete: null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Du coup y'a pas besoin de cette propriété, si ? |
||
onTick: dumpDatabase, | ||
timeZone: "Europe/Paris" | ||
}); | ||
|
||
export const deleteOldDumpJob = CronJob.from({ | ||
start: false, | ||
cronTime: "0 30 4 * * *", | ||
onComplete: null, | ||
onTick: removeOldDumps, | ||
timeZone: "Europe/Paris" | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ import APIHandler from "@/api"; | |
import StaticHandler from "@/static"; | ||
import UploadHandler from "@/upload"; | ||
import PageHandler from "@/page"; | ||
import * as cron from "@/cronjob"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Si tu les start directement, tu peux juste import le fichier
|
||
|
||
|
||
//import NotFoundHandler from "@/notFound"; | ||
|
||
async function init() { | ||
|
@@ -50,3 +53,6 @@ process.on("SIGINT", async function() { | |
await closeDatabase(); | ||
process.exit(1); | ||
}); | ||
|
||
cron.dumpDatabaseJob.start(); | ||
cron.deleteOldDumpJob.start(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { promises as pfs } from "node:fs"; | ||
import * as cs from "cross-spawn"; | ||
|
||
const BACKUP_RETENTION_DAYS = 30; | ||
|
||
export async function dumpDatabase() { | ||
const dumpDate = new Date().toLocaleDateString("fr-fr",{ day: "2-digit", month: "2-digit", year: "numeric" }).replaceAll("/", "-"); | ||
const folderName = `../dumps/${ dumpDate }`; | ||
await pfs.mkdir(folderName, { recursive: true }); | ||
|
||
const child = cs.spawn("mongodump", ["--db", "sgnw", "--out", `../dumps/${ dumpDate }`], { stdio: "inherit" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ça serait peut être pas mal de mettre le path vers mongodump dans le |
||
} | ||
|
||
export async function removeOldDumps() { | ||
const currentDate = new Date(); | ||
const folderName = "../dumps/"; | ||
|
||
const dirs = await pfs.readdir(folderName,{ encoding: "utf-8" }); | ||
dirs.forEach(async (dir) => { | ||
const [day, month, year] = dir.split("-").map(Number); | ||
const dumpDate = new Date(year, month - 1, day); | ||
const Difference_In_Days = Math.floor((currentDate.getTime() - dumpDate.getTime()) / (1000 * 3600 * 24)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il y a le package |
||
|
||
if (Difference_In_Days > BACKUP_RETENTION_DAYS) { | ||
pfs.rm(`${ folderName }/${ dir }`, { recursive: true }); | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ | |
"exclude": [ | ||
"node_modules" | ||
] | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pourquoi y'a cette modif 🤔 ? L'eslint devrait garder les lignes vide à la fin normalement, non ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai enfin compris. J'ai ajouté ces lignes à mon . "eslint.workingDirectories": [
{
"mode": "auto"
}
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi pas le start directement 🤔 ?