Skip to content

Commit

Permalink
await Promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
nmagedman committed Jan 20, 2025
1 parent 5f9fbba commit 98c4782
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions apps/meteor/app/seeking-alpha/terms-of-use-violations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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) {
Expand Down

0 comments on commit 98c4782

Please sign in to comment.