act-now-coalition/covid-act-now-website

Update GH Action for Email Alerts to Accept "0 New Emails Sent" as Potentially Valid

Closed this issue · 3 comments

New Edge Case!

Currently we have logic to terminate with Exit Code 1 if we tried to send emails, but our counter does not register any sent emails.

In the new "low covid and low reporting regime" it's more likely that we may have no significant score changes over the weekend (especially if our end-of-week alerts grabs the big changes from Thursday of previous week).

So now the expectation is that a "0 send" could be valid. Let's update the logic so that significant errors still terminates with an Exit Code 1, but "0 send" just gets logged to console.

if (emailSent < 1 || errorCount > 1) {
console.log(
`Error count: ${errorCount}. Emails sent: ${emailSent}. Invalid emails removed: ${invalidEmailCount}`,
);
process.exit(1);

Hii there ...
We can update the logic as:

if (errorCount > 1) {
  console.log(
    `Error count: ${errorCount}. Emails sent: ${emailSent}. Invalid emails removed: ${invalidEmailCount}`,
  );
  process.exit(1);
} else if (emailSent === 0) {
  console.log("No emails were sent.");
} else {
  console.log(
    `Emails sent: ${emailSent}. Invalid emails removed: ${invalidEmailCount}`,
  );
}

//In this code snippet:

//- If the `errorCount` is greater than 1, an error message is logged to the console. It includes the values of `errorCount`, `emailSent`, and `invalidEmailCount`. The process is then exited with an exit code of 1.
//- If `emailSent` is equal to 0, a message stating "No emails were sent." is logged to the console.
//- If none of the above conditions are met, the number of emails sent (`emailSent`) and the count of invalid emails removed (`invalidEmailCount`) are logged to the console.

If this is write i can create a PR ....

Hi @hardiksharma11. Thanks for offering to help. At this moment we are doing a larger refactor of some of the GH actions, and as such, are planning on leaving this as-is for right now. Thank you for the interest though.