Fix crash when cron seed file is missing

This commit is contained in:
Girish Ramakrishnan
2022-08-10 22:07:05 +02:00
parent 251c1f9757
commit b5cc7d90a9
2 changed files with 7 additions and 8 deletions

View File

@@ -140,7 +140,7 @@ async function runStartupTasks() {
// we used to run tasks in parallel but simultaneous nginx reloads was causing issues
for (let i = 0; i < tasks.length; i++) {
const [error] = await safe(tasks[i]());
if (error) debug(`Startup task at index ${i} failed: ${error.message}`);
if (error) debug(`Startup task at index ${i} failed: ${error.message} ${error.stack}`);
}
}

View File

@@ -66,15 +66,14 @@ function getCronSeed() {
let hour = null;
let minute = null;
let tmp = safe.fs.readFileSync(paths.CRON_SEED_FILE, 'utf8');
if (tmp) tmp = tmp.split(':');
if (tmp.length === 2) {
hour = parseInt(tmp[0]);
minute = parseInt(tmp[1]);
const seedData = safe.fs.readFileSync(paths.CRON_SEED_FILE, 'utf8') || '';
const parts = seedData.split(':');
if (parts.length === 2) {
hour = parseInt(parts[0]) || null;
minute = parseInt(parts[1]) || null;
}
if ((isNaN(hour) || hour < 0 || hour > 23) || (isNaN(minute) || minute < 0 || minute > 60)) {
if ((hour == null || hour < 0 || hour > 23) || (minute == null || minute < 0 || minute > 60)) {
hour = Math.floor(24 * Math.random());
minute = Math.floor(60 * Math.random());