diff --git a/apps/meteor/app/seeking-alpha/terms-of-use-violations/index.ts b/apps/meteor/app/seeking-alpha/terms-of-use-violations/index.ts index 062ffa0e06b71..25015ac0c4c20 100644 --- a/apps/meteor/app/seeking-alpha/terms-of-use-violations/index.ts +++ b/apps/meteor/app/seeking-alpha/terms-of-use-violations/index.ts @@ -43,10 +43,15 @@ Meteor.startup(async () => { async function perform() { const slack = new Slack(SLACK_TOKEN); const attachments = []; + const promises = TERMS_TO_MONITOR.map( + keyword => aggregateMessagesContainingKeyword(keyword, nDaysBeforeDate(14, today())) + ); - TERMS_TO_MONITOR.forEach(async (keyword) => { - const docs = await aggregateMessagesContainingKeyword(keyword, nDaysBeforeDate(14, today())); // yesterday()); - LOG.info(`docs = ${docs} [${typeof docs}]`); + const aggregations = await Promise.all(promises); + + TERMS_TO_MONITOR.forEach((keyword, i) => { + const docs = aggregations[i]; + LOG.info(`docs => (${typeof docs}, isArray? ${Array.isArray(docs)}) ${docs}`); if (docs) { attachments.push({ filename: `${keyword}.tsv`, @@ -58,10 +63,12 @@ async function perform() { LOG.info(`attachments.length == ${attachments.length}`); if (attachments.length === 0) { - slack.post_message(SLACK_CHANNEL_ID, "No RocketChat TOU violations today!") + slack.post_message(SLACK_CHANNEL_ID, "No RocketChat TOU violations today!"); } else { + LOG.info("Posting to Slack: RocketChat TOU Violations (with attachments)"); slack.post_attachments(SLACK_CHANNEL_ID, attachments, "RocketChat TOU Violations:"); } + LOG.info("Posted to Slack!"); } function aggregateMessagesContainingKeyword(keyword, date) {