0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

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
This commit is contained in:
Kevin Ansfield 2020-12-01 11:27:34 +00:00
parent ddcdaa6193
commit 641be8fec3

View file

@ -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'