1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-12-24 22:14:47 +02:00
uptime-kuma/server/jobs.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-05-12 18:55:48 +02:00
const { UptimeKumaServer } = require("./uptime-kuma-server");
const { clearOldData } = require("./jobs/clear-old-data");
const { incrementalVacuum } = require("./jobs/incremental-vacuum");
2023-05-12 18:55:48 +02:00
const Cron = require("croner");
const jobs = [
{
name: "clear-old-data",
2023-05-12 18:55:48 +02:00
interval: "14 03 * * *",
jobFunc: clearOldData,
croner: null,
2021-10-23 15:44:21 +02:00
},
{
name: "incremental-vacuum",
interval: "*/5 * * * *",
jobFunc: incrementalVacuum,
croner: null,
}
];
/**
* Initialize background jobs
2023-05-12 18:55:48 +02:00
* @returns {Promise<void>}
*/
2023-05-12 18:55:48 +02:00
const initBackgroundJobs = async function () {
const timezone = await UptimeKumaServer.getInstance().getTimezone();
for (const job of jobs) {
const cornerJob = new Cron(
job.interval,
{
name: job.name,
timezone,
},
job.jobFunc,
);
job.croner = cornerJob;
}
};
/**
* Stop all background jobs if running
* @returns {void}
*/
const stopBackgroundJobs = function () {
2023-05-12 18:55:48 +02:00
for (const job of jobs) {
if (job.croner) {
job.croner.stop();
job.croner = null;
}
}
};
module.exports = {
initBackgroundJobs,
stopBackgroundJobs
};