2020-11-04 08:35:37 -05:00
|
|
|
const Queue = require('bull')
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
|
2021-01-28 08:40:18 -05:00
|
|
|
// Bull will keep a fixed number of the most recently completed jobs. This is
|
|
|
|
// useful to inspect recently completed jobs. The bull prometheus exporter also
|
|
|
|
// uses the completed job records to report on job duration.
|
|
|
|
const MAX_COMPLETED_JOBS_RETAINED = 10000
|
2021-02-17 05:05:04 -05:00
|
|
|
const MAX_FAILED_JOBS_RETAINED = 50000
|
2021-01-28 08:40:18 -05:00
|
|
|
|
2021-03-31 05:24:39 -04:00
|
|
|
const queues = {}
|
|
|
|
|
|
|
|
function getAnalyticsEventsQueue() {
|
|
|
|
if (Settings.analytics.enabled) {
|
|
|
|
return getOrCreateQueue('analytics-events')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAnalyticsEditingSessionsQueue() {
|
2020-11-12 09:09:41 -05:00
|
|
|
if (Settings.analytics.enabled) {
|
2021-03-31 05:24:39 -04:00
|
|
|
return getOrCreateQueue('analytics-editing-sessions')
|
2020-11-12 09:09:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-31 05:24:39 -04:00
|
|
|
function getOnboardingEmailsQueue() {
|
|
|
|
return getOrCreateQueue('emails-onboarding')
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOrCreateQueue(queueName, defaultJobOptions) {
|
|
|
|
if (!queues[queueName]) {
|
|
|
|
queues[queueName] = new Queue(queueName, {
|
|
|
|
redis: Settings.redis.queues,
|
|
|
|
defaultJobOptions: {
|
|
|
|
removeOnComplete: MAX_COMPLETED_JOBS_RETAINED,
|
|
|
|
removeOnFail: MAX_FAILED_JOBS_RETAINED,
|
|
|
|
attempts: 11,
|
|
|
|
backoff: {
|
|
|
|
type: 'exponential',
|
2021-04-27 03:52:58 -04:00
|
|
|
delay: 3000,
|
|
|
|
},
|
|
|
|
},
|
2021-03-31 05:24:39 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return queues[queueName]
|
2020-11-04 08:35:37 -05:00
|
|
|
}
|
|
|
|
|
2021-03-31 05:24:39 -04:00
|
|
|
module.exports = {
|
|
|
|
getAnalyticsEventsQueue,
|
|
|
|
getAnalyticsEditingSessionsQueue,
|
2021-04-27 03:52:58 -04:00
|
|
|
getOnboardingEmailsQueue,
|
2021-03-31 05:24:39 -04:00
|
|
|
}
|