From d08e30f1d6b9ffc8b9276f3313620dc9fd49c945 Mon Sep 17 00:00:00 2001 From: Michal Landsman Date: Thu, 12 Mar 2026 18:43:49 +0100 Subject: [PATCH] feat: sentry cron monitoring --- supabase/functions/_shared/sentry.ts | 16 ++++++++++++++++ .../functions/lastfm-library-artists/index.ts | 13 ++++++++++++- .../functions/lastfm-user-recent-tracks/index.ts | 13 ++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/supabase/functions/_shared/sentry.ts b/supabase/functions/_shared/sentry.ts index 514f0e5..e2bf1f5 100644 --- a/supabase/functions/_shared/sentry.ts +++ b/supabase/functions/_shared/sentry.ts @@ -47,4 +47,20 @@ export class SentryErrorHandler { } console.error(e); } + + /** + * Wraps a cron job function with Sentry Cron Monitoring check-ins. + * Reports in_progress at start, ok on success, error on failure. + * In non-production mode, the function runs without any Sentry calls. + */ + withCronMonitor( + monitorSlug: string, + monitorConfig: Sentry.MonitorConfig, + fn: () => Promise, + ): Promise { + if (!this.isProduction) { + return fn(); + } + return Sentry.withMonitor(monitorSlug, fn, monitorConfig); + } } diff --git a/supabase/functions/lastfm-library-artists/index.ts b/supabase/functions/lastfm-library-artists/index.ts index 81b0c4a..ce98bee 100644 --- a/supabase/functions/lastfm-library-artists/index.ts +++ b/supabase/functions/lastfm-library-artists/index.ts @@ -9,7 +9,18 @@ sentryHandler.init(); Deno.serve(async (req) => { try { const lastFmUser = await getLastFmUser(req, env.LASTFM_USERNAME); - const result = await syncArtists(env, lastFmUser); + const monitorSlug = `lastfm_library_artists_${lastFmUser.toLowerCase()}`; + + const result = await sentryHandler.withCronMonitor( + monitorSlug, + { + schedule: { type: "crontab", value: "*/30 * * * *" }, + checkinMargin: 10, + maxRuntime: 25, + timezone: "UTC", + }, + () => syncArtists(env, lastFmUser), + ); return new Response(result, { status: 200, diff --git a/supabase/functions/lastfm-user-recent-tracks/index.ts b/supabase/functions/lastfm-user-recent-tracks/index.ts index ea37f3f..c11c0ea 100644 --- a/supabase/functions/lastfm-user-recent-tracks/index.ts +++ b/supabase/functions/lastfm-user-recent-tracks/index.ts @@ -9,7 +9,18 @@ sentryHandler.init(); Deno.serve(async (req) => { try { const lastFmUser = await getLastFmUser(req, env.LASTFM_USERNAME); - const result = await syncTracks(env, lastFmUser); + const monitorSlug = `lastfm_user_recent_tracks_${lastFmUser.toLowerCase()}`; + + const result = await sentryHandler.withCronMonitor( + monitorSlug, + { + schedule: { type: "crontab", value: "*/5 * * * *" }, + checkinMargin: 5, + maxRuntime: 4, + timezone: "UTC", + }, + () => syncTracks(env, lastFmUser), + ); return new Response(result, { status: 200,