From 641be8fec3d1577b0fb123ea048e29740a2ce150 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 1 Dec 2020 11:27:34 +0000 Subject: [PATCH] Adjusted email analytics job scheduling to avoid API spikes no issue - typically cron/later schedules will schedule for :00 on the minute which would create API spikes with every members-email-using Ghost site hitting the API at the same time - adjusted the scheduling to use cron syntax with job runs every 2 minutes on 1,3,5... or 2,4,6... and a random seconds value to smooth usage across sites --- core/server/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/server/index.js b/core/server/index.js index 660c413a20..f09c77e34d 100644 --- a/core/server/index.js +++ b/core/server/index.js @@ -79,8 +79,13 @@ function initializeRecurringJobs() { const jobsService = require('./services/jobs'); if (config.get('backgroundJobs:emailAnalytics')) { + // use a random seconds value to avoid spikes to external APIs on the minute + const s = Math.floor(Math.random() * 60); // 0-59 + // run every 2 minutes, either on 1,3,5... or 2,4,6... + const m = Math.floor(Math.random() * 2) + 1; // 1-2 + jobsService.scheduleJob( - 'every 1 minute', + `${s} ${m}/2 * * * *`, path.resolve(__dirname, 'services', 'email-analytics', 'jobs', 'fetch-latest.js'), undefined, 'email-analytics-fetch-latest'