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:
parent
ddcdaa6193
commit
641be8fec3
1 changed files with 6 additions and 1 deletions
|
@ -79,8 +79,13 @@ function initializeRecurringJobs() {
|
||||||
const jobsService = require('./services/jobs');
|
const jobsService = require('./services/jobs');
|
||||||
|
|
||||||
if (config.get('backgroundJobs:emailAnalytics')) {
|
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(
|
jobsService.scheduleJob(
|
||||||
'every 1 minute',
|
`${s} ${m}/2 * * * *`,
|
||||||
path.resolve(__dirname, 'services', 'email-analytics', 'jobs', 'fetch-latest.js'),
|
path.resolve(__dirname, 'services', 'email-analytics', 'jobs', 'fetch-latest.js'),
|
||||||
undefined,
|
undefined,
|
||||||
'email-analytics-fetch-latest'
|
'email-analytics-fetch-latest'
|
||||||
|
|
Loading…
Reference in a new issue