update cron module

CronJob -> CronJob.from
CronJob(time) -> CronTime
This commit is contained in:
Girish Ramakrishnan
2024-04-19 18:19:41 +02:00
parent a926a3e8a8
commit d137cdf881
7 changed files with 38 additions and 60 deletions

View File

@@ -27,7 +27,7 @@ const appHealthMonitor = require('./apphealthmonitor.js'),
backups = require('./backups.js'),
cloudron = require('./cloudron.js'),
constants = require('./constants.js'),
CronJob = require('cron').CronJob,
{ CronJob } = require('cron'),
debug = require('debug')('box:cron'),
dyndns = require('./dyndns.js'),
externalLdap = require('./externalldap.js'),
@@ -99,75 +99,75 @@ async function startJobs() {
debug(`startJobs: starting cron jobs with hour ${hour} and minute ${minute}`);
gJobs.systemChecks = new CronJob({
gJobs.systemChecks = CronJob.from({
cronTime: `00 ${minute} 2 * * *`, // once a day. if you change this interval, change the notification messages with correct duration
onTick: async () => await safe(system.runSystemChecks(), { debug }),
start: true
});
gJobs.mailStatusCheck = new CronJob({
gJobs.mailStatusCheck = CronJob.from({
cronTime: `00 ${minute} 2 * * *`, // once a day. if you change this interval, change the notification messages with correct duration
onTick: async () => await safe(mail.checkStatus(), { debug }),
start: true
});
gJobs.diskUsage = new CronJob({
gJobs.diskUsage = CronJob.from({
cronTime: `00 ${minute} 3 * * *`, // once a day
onTick: async () => await safe(system.startUpdateDiskUsage(), { debug }),
start: true
});
gJobs.diskSpaceChecker = new CronJob({
gJobs.diskSpaceChecker = CronJob.from({
cronTime: '00 30 * * * *', // every 30 minutes. if you change this interval, change the notification messages with correct duration
onTick: async () => await safe(system.checkDiskSpace(), { debug }),
start: true
});
// this is run separately from the update itself so that the user can disable automatic updates but can still get a notification
gJobs.updateCheckerJob = new CronJob({
gJobs.updateCheckerJob = CronJob.from({
cronTime: `00 ${minute} 1,5,9,13,17,21,23 * * *`,
onTick: async () => await safe(updateChecker.checkForUpdates({ automatic: true }), { debug }),
start: true
});
gJobs.cleanupTokens = new CronJob({
gJobs.cleanupTokens = CronJob.from({
cronTime: '00 */30 * * * *', // every 30 minutes
onTick: async () => await safe(janitor.cleanupTokens(), { debug }),
start: true
});
gJobs.cleanupBackups = new CronJob({
gJobs.cleanupBackups = CronJob.from({
cronTime: DEFAULT_CLEANUP_BACKUPS_PATTERN,
onTick: async () => await safe(backups.startCleanupTask(AuditSource.CRON), { debug }),
start: true
});
gJobs.cleanupEventlog = new CronJob({
gJobs.cleanupEventlog = CronJob.from({
cronTime: '00 */30 * * * *', // every 30 minutes
onTick: async () => await safe(eventlog.cleanup({ creationTime: new Date(Date.now() - 90 * 60 * 24 * 60 * 1000) }), { debug }), // 90 days ago
start: true
});
gJobs.dockerVolumeCleaner = new CronJob({
gJobs.dockerVolumeCleaner = CronJob.from({
cronTime: '00 00 */12 * * *', // every 12 hours
onTick: async () => await safe(janitor.cleanupDockerVolumes(), { debug }),
start: true
});
gJobs.schedulerSync = new CronJob({
gJobs.schedulerSync = CronJob.from({
cronTime: constants.TEST ? '*/10 * * * * *' : '00 */1 * * * *', // every minute
onTick: async () => await safe(scheduler.sync(), { debug }),
start: true
});
// randomized per Cloudron based on hourlySeed
gJobs.certificateRenew = new CronJob({
gJobs.certificateRenew = CronJob.from({
cronTime: `00 10 ${hour} * * *`,
onTick: async () => await safe(reverseProxy.startRenewCerts({}, AuditSource.CRON), { debug }),
start: true
});
gJobs.appHealthMonitor = new CronJob({
gJobs.appHealthMonitor = CronJob.from({
cronTime: '*/10 * * * * *', // every 10 seconds
onTick: async () => await safe(appHealthMonitor.run(10), { debug }), // 10 is the max run time
start: true
@@ -189,7 +189,7 @@ async function handleBackupPolicyChanged(value) {
if (gJobs.backup) gJobs.backup.stop();
gJobs.backup = null;
gJobs.backup = new CronJob({
gJobs.backup = CronJob.from({
cronTime: value.schedule,
onTick: async () => await safe(backups.startBackupTask(AuditSource.CRON), { debug }),
start: true,
@@ -217,7 +217,7 @@ async function handleAutoupdatePatternChanged(pattern) {
if (pattern === constants.AUTOUPDATE_PATTERN_NEVER) return;
gJobs.autoUpdater = new CronJob({
gJobs.autoUpdater = CronJob.from({
cronTime: pattern,
onTick: async function() {
const updateInfo = updateChecker.getUpdateInfo();
@@ -255,7 +255,7 @@ function handleDynamicDnsChanged(enabled) {
if (!enabled) return;
gJobs.dynamicDns = new CronJob({
gJobs.dynamicDns = CronJob.from({
// until we can be smarter about actual IP changes, lets ensure it every 10minutes
cronTime: '00 */10 * * * *',
onTick: async () => { await safe(dyndns.refreshDns(AuditSource.CRON), { debug }); },
@@ -271,7 +271,7 @@ async function handleExternalLdapChanged(config) {
if (config.provider === 'noop') return;
gJobs.externalLdapSyncer = new CronJob({
gJobs.externalLdapSyncer = CronJob.from({
cronTime: '00 00 */4 * * *', // every 4 hours
onTick: async () => await safe(externalLdap.startSyncer(AuditSource.CRON), { debug }),
start: true