Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
fix(workflows): log email batch failures with context and Sentry cron status (#2589)
polylane[bot]a69aab3fa989
diff --git a/apps/workflows/src/cron/emails.ts b/apps/workflows/src/cron/emails.tsindex 4426493a6..235d4d548 100644--- a/apps/workflows/src/cron/emails.ts+++ b/apps/workflows/src/cron/emails.ts@@ -1,3 +1,4 @@+import { getLogger } from "@logtape/logtape";import { and, eq, gte, inArray, lte } from "@openstatus/db";import { db } from "@openstatus/db";import {@@ -9,6 +10,7 @@ import { EmailClient } from "@openstatus/emails";import { env } from "../env";+const logger = getLogger(["workflow", "emails"]);const email = new EmailClient({ apiKey: env().RESEND_API_KEY });export async function sendFollowUpEmails() {@@ -27,8 +29,6 @@ export async function sendFollowUpEmails() {.where(and(gte(user.createdAt, date1), lte(user.createdAt, date2))).all();- console.log(`Found ${users.length} users to send follow ups.`);-const workspaceIds = [...new Set(users.map((u) => u.workspaceId).filter(Boolean)),];@@ -71,22 +71,26 @@ export async function sendFollowUpEmails() {for (let i = 0; i < noSlackEmails.length; i += batchSize) {const batch = noSlackEmails.slice(i, i + batchSize);- console.log(`Sending follow-up batch with ${batch.length} emails...`);try {await email.sendFollowUpBatched({ to: batch });- } catch {- console.error("Rate limit exceeded. Stopping further sends.");+ } catch (error) {+ logger.error("Follow-up email batch failed", {+ batch_size: batch.length,+ error_name: error instanceof Error ? error.name : typeof error,+ });break;}}for (let i = 0; i < slackEmails.length; i += batchSize) {const batch = slackEmails.slice(i, i + batchSize);- console.log(`Sending slack feedback batch with ${batch.length} emails...`);try {await email.sendSlackFeedbackBatched({ to: batch });- } catch {- console.error("Rate limit exceeded. Stopping further sends.");+ } catch (error) {+ logger.error("Slack feedback email batch failed", {+ batch_size: batch.length,+ error_name: error instanceof Error ? error.name : typeof error,+ });break;}}diff --git a/apps/workflows/src/cron/index.ts b/apps/workflows/src/cron/index.tsindex 3a9a9caa2..c5096571b 100644--- a/apps/workflows/src/cron/index.ts+++ b/apps/workflows/src/cron/index.ts@@ -104,11 +104,16 @@ app.get("/private-location-health", async (c) => {});app.get("/emails/follow-up", async (c) => {+ const { cronCompleted, cronFailed } = runSentryCron("emails-follow-up");+try {await sendFollowUpEmails();+ void cronCompleted();return c.json({ success: true }, 200);} catch (e) {- console.error(e);+ const errorName = e instanceof Error ? e.name : typeof e;+ void reportBackgroundError(`emails-follow-up failed: ${errorName}`);+ void cronFailed();return c.text("Internal Server Error", 500);}});