diff --git a/src/data-layer/tasks.ts b/src/data-layer/tasks.ts index def277b642c..929bef14d3e 100644 --- a/src/data-layer/tasks.ts +++ b/src/data-layer/tasks.ts @@ -5,7 +5,7 @@ * Hourly tasks run every hour. */ -import { schedules, task } from "@trigger.dev/sdk/v3" +import { schedules, task, tasks } from "@trigger.dev/sdk/v3" import { fetchApps } from "./fetchers/fetchApps" import { fetchBeaconChain } from "./fetchers/fetchBeaconChain" @@ -122,3 +122,24 @@ export const hourlyTask = schedules.task({ cron: "0 * * * *", run: () => Promise.all(hourlyFetchTasks.map((t) => t.trigger())), }) + +// ─── Global failure handler → Discord ─── +tasks.onFailure(async ({ ctx, error }) => { + const webhookUrl = process.env.DISCORD_WEBHOOK_URL + if (!webhookUrl) return + + await fetch(webhookUrl, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + embeds: [ + { + title: `Data Fetch Failed: ${ctx.task.id}`, + color: 0xff0000, + description: String(error).slice(0, 2000), + timestamp: new Date().toISOString(), + }, + ], + }), + }) +})