mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-04 09:42:56 +02:00
8a92054c2b
* Added JSDoc to eslint rules Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Fixed JSDoc eslint errors Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Update the check-linters workflow to Node.js 20 --------- Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
const { UptimeKumaServer } = require("./uptime-kuma-server");
|
|
const { clearOldData } = require("./jobs/clear-old-data");
|
|
const { incrementalVacuum } = require("./jobs/incremental-vacuum");
|
|
const Cron = require("croner");
|
|
|
|
const jobs = [
|
|
{
|
|
name: "clear-old-data",
|
|
interval: "14 03 * * *",
|
|
jobFunc: clearOldData,
|
|
croner: null,
|
|
},
|
|
{
|
|
name: "incremental-vacuum",
|
|
interval: "*/5 * * * *",
|
|
jobFunc: incrementalVacuum,
|
|
croner: null,
|
|
}
|
|
];
|
|
|
|
/**
|
|
* Initialize background jobs
|
|
* @returns {Promise<void>}
|
|
*/
|
|
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 () {
|
|
for (const job of jobs) {
|
|
if (job.croner) {
|
|
job.croner.stop();
|
|
job.croner = null;
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
initBackgroundJobs,
|
|
stopBackgroundJobs
|
|
};
|