feat: check status of repository

This commit is contained in:
tdurieux
2021-09-06 09:39:05 +02:00
parent 49da267d5f
commit cbbc43f280
3 changed files with 21 additions and 3 deletions

View File

@@ -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();
}

View File

@@ -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();
});
});
}

View File

@@ -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);