diff --git a/src/mailer.js b/src/mailer.js index c96deb4f..f36c2027 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -86,6 +86,11 @@ const templates = {
`, }, + cardsWarning: { + subject: 'Cards queue is getting long', + text: 'There\'s {{count}} cards in the queue!', + html: 'There\'s {{count}} cards in the queue!
', + } } const applyTemplate = (template, context, params) => { diff --git a/src/stats.js b/src/stats.js index 6313667a..8c2a7328 100644 --- a/src/stats.js +++ b/src/stats.js @@ -1,4 +1,5 @@ const {decodeTime} = require('ulid'); +const mailer = require('./mailer'); // TODO all the duplication... const buildDict = (fn, ...args) => { @@ -113,5 +114,9 @@ module.exports.calculateStats = async (db, allLocales) => { const cardsQueue = (await db.get(`SELECT count(*) as c FROM profiles WHERE card = '' OR cardDark = ''`)).c; + if (cardsQueue > 64) { + mailer('andrea@avris.it', 'cardsWarning', {count: cardsQueue}); + } + return { calculatedAt: parseInt(new Date() / 1000), users, locales, cardsQueue }; }