From cbbc43f280bb3139872fe6cefcafc3745efc2818 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 6 Sep 2021 09:39:05 +0200 Subject: [PATCH] feat: check status of repository --- src/Repository.ts | 5 ++++- src/schedule.ts | 16 +++++++++++++++- src/server.ts | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Repository.ts b/src/Repository.ts index 7738e40..4af1d71 100644 --- a/src/Repository.ts +++ b/src/Repository.ts @@ -93,7 +93,10 @@ export default class Repository { * Check the status of the repository */ check() { - if (this._model.options.expirationMode !== "never") { + if ( + this._model.options.expirationMode !== "never" && + this._model.status == "ready" + ) { if (this._model.options.expirationDate <= new Date()) { this.expire(); } diff --git a/src/schedule.ts b/src/schedule.ts index c848b8e..6862650 100644 --- a/src/schedule.ts +++ b/src/schedule.ts @@ -1,9 +1,11 @@ import * as schedule from "node-schedule"; import Conference from "./Conference"; +import AnonymizedRepositoryModel from "./database/anonymizedRepositories/anonymizedRepositories.model"; import ConferenceModel from "./database/conference/conferences.model"; +import Repository from "./Repository"; export function conferenceStatusCheck() { - // check every 6 hours the status of the conference + // check every 6 hours the status of the conferences const job = schedule.scheduleJob("0 */6 * * *", async () => { (await ConferenceModel.find({ status: { $eq: "ready" } })).forEach( async (data) => { @@ -15,3 +17,15 @@ export function conferenceStatusCheck() { ); }); } + +export function repositoryStatusCheck() { + // check every 6 hours the status of the repositories + const job = schedule.scheduleJob("0 */6 * * *", async () => { + ( + await AnonymizedRepositoryModel.find({ status: { $eq: "ready" } }) + ).forEach((data) => { + const repo = new Repository(data); + repo.check(); + }); + }); +} diff --git a/src/server.ts b/src/server.ts index 32a78bf..57a54dd 100644 --- a/src/server.ts +++ b/src/server.ts @@ -12,7 +12,7 @@ import * as passport from "passport"; import * as connection from "./routes/connection"; import router from "./routes"; import AnonymizedRepositoryModel from "./database/anonymizedRepositories/anonymizedRepositories.model"; -import { conferenceStatusCheck } from "./schedule"; +import { conferenceStatusCheck, repositoryStatusCheck } from "./schedule"; function indexResponse(req: express.Request, res: express.Response) { if ( @@ -100,6 +100,7 @@ export default async function start() { // start schedules conferenceStatusCheck(); + repositoryStatusCheck(); await db.connect(); app.listen(config.PORT);