Openstatus www.openstatus.dev

fix: smaller bugs (#1135)

* fix: timestamp

* fix: sentry

authored by

Maximilian Kaske and committed by
GitHub
b71c81af 64f605d1

+79 -69
+8 -13
apps/web/src/app/api/checker/cron/10m/route.ts
··· 1 - import * as Sentry from "@sentry/nextjs"; 2 1 import type { NextRequest } from "next/server"; 3 2 import { NextResponse } from "next/server"; 4 3 5 4 import { cron, isAuthorizedDomain } from "../_cron"; 5 + import { runSentryCron } from "../_sentry"; 6 6 7 7 export const runtime = "nodejs"; 8 8 // export const preferredRegion = ["auto"]; ··· 12 12 13 13 export async function GET(req: NextRequest) { 14 14 if (isAuthorizedDomain(req.url)) { 15 - const checkInId = Sentry.captureCheckIn({ 16 - monitorSlug: "10-min-cron", 17 - status: "in_progress", 18 - }); 19 - 20 - await cron({ periodicity: "10m", req }); 21 - 22 - Sentry.captureCheckIn({ 23 - checkInId, 24 - monitorSlug: "10-min-cron", 25 - status: "ok", 26 - }); 15 + const { cronCompleted, cronFailed } = runSentryCron("10-m-cron"); 16 + try { 17 + await cron({ periodicity: "10m", req }); 18 + await cronCompleted(); 19 + } catch (error) { 20 + await cronFailed(); 21 + } 27 22 } 28 23 return NextResponse.json({ success: true }); 29 24 }
+8 -11
apps/web/src/app/api/checker/cron/1h/route.ts
··· 1 - import * as Sentry from "@sentry/nextjs"; 2 1 import type { NextRequest } from "next/server"; 3 2 import { NextResponse } from "next/server"; 4 3 5 4 import { cron, isAuthorizedDomain } from "../_cron"; 5 + import { runSentryCron } from "../_sentry"; 6 6 7 7 export const runtime = "nodejs"; 8 8 // export const preferredRegion = ["auto"]; ··· 12 12 13 13 export async function GET(req: NextRequest) { 14 14 if (isAuthorizedDomain(req.url)) { 15 - const checkInId = Sentry.captureCheckIn({ 16 - monitorSlug: "1-h-cron", 17 - status: "in_progress", 18 - }); 19 - await cron({ periodicity: "1h", req }); 20 - Sentry.captureCheckIn({ 21 - checkInId, 22 - monitorSlug: "1-h-cron", 23 - status: "ok", 24 - }); 15 + const { cronCompleted, cronFailed } = runSentryCron("1-h-cron"); 16 + try { 17 + await cron({ periodicity: "1h", req }); 18 + await cronCompleted(); 19 + } catch (error) { 20 + await cronFailed(); 21 + } 25 22 } 26 23 return NextResponse.json({ success: true }); 27 24 }
+8 -11
apps/web/src/app/api/checker/cron/1m/route.ts
··· 1 - import * as Sentry from "@sentry/nextjs"; 2 1 import type { NextRequest } from "next/server"; 3 2 import { NextResponse } from "next/server"; 4 3 5 4 import { cron, isAuthorizedDomain } from "../_cron"; 5 + import { runSentryCron } from "../_sentry"; 6 6 7 7 export const runtime = "nodejs"; 8 8 // export const preferredRegion = ["auto"]; ··· 12 12 13 13 export async function GET(req: NextRequest) { 14 14 if (isAuthorizedDomain(req.url)) { 15 - const checkInId = Sentry.captureCheckIn({ 16 - monitorSlug: "1-min-cron", 17 - status: "in_progress", 18 - }); 19 - await cron({ periodicity: "1m", req }); 20 - Sentry.captureCheckIn({ 21 - checkInId, 22 - monitorSlug: "1-min-cron", 23 - status: "ok", 24 - }); 15 + const { cronCompleted, cronFailed } = runSentryCron("1-m-cron"); 16 + try { 17 + await cron({ periodicity: "1m", req }); 18 + await cronCompleted(); 19 + } catch (error) { 20 + await cronFailed(); 21 + } 25 22 } 26 23 return NextResponse.json({ success: true }); 27 24 }
+8 -11
apps/web/src/app/api/checker/cron/30m/route.ts
··· 1 - import * as Sentry from "@sentry/nextjs"; 2 1 import type { NextRequest } from "next/server"; 3 2 import { NextResponse } from "next/server"; 4 3 5 4 import { cron, isAuthorizedDomain } from "../_cron"; 5 + import { runSentryCron } from "../_sentry"; 6 6 7 7 export const runtime = "nodejs"; 8 8 // export const preferredRegion = ["auto"]; ··· 12 12 13 13 export async function GET(req: NextRequest) { 14 14 if (isAuthorizedDomain(req.url)) { 15 - const checkInId = Sentry.captureCheckIn({ 16 - monitorSlug: "30-min-cron", 17 - status: "in_progress", 18 - }); 19 - await cron({ periodicity: "30m", req }); 20 - Sentry.captureCheckIn({ 21 - checkInId, 22 - monitorSlug: "30-min-cron", 23 - status: "ok", 24 - }); 15 + const { cronCompleted, cronFailed } = runSentryCron("30-m-cron"); 16 + try { 17 + await cron({ periodicity: "30m", req }); 18 + await cronCompleted(); 19 + } catch (error) { 20 + await cronFailed(); 21 + } 25 22 } 26 23 return NextResponse.json({ success: true }); 27 24 }
+8 -11
apps/web/src/app/api/checker/cron/30s/route.ts
··· 1 - import * as Sentry from "@sentry/nextjs"; 2 1 import type { NextRequest } from "next/server"; 3 2 import { NextResponse } from "next/server"; 4 3 5 4 import { cron, isAuthorizedDomain } from "../_cron"; 5 + import { runSentryCron } from "../_sentry"; 6 6 7 7 export const runtime = "nodejs"; 8 8 // export const preferredRegion = ["auto"]; ··· 12 12 13 13 export async function GET(req: NextRequest) { 14 14 if (isAuthorizedDomain(req.url)) { 15 - const checkInId = Sentry.captureCheckIn({ 16 - monitorSlug: "30-s-cron", 17 - status: "in_progress", 18 - }); 19 - await cron({ periodicity: "30s", req }); 20 - Sentry.captureCheckIn({ 21 - checkInId, 22 - monitorSlug: "30-s-cron", 23 - status: "ok", 24 - }); 15 + const { cronCompleted, cronFailed } = runSentryCron("30-s-cron"); 16 + try { 17 + await cron({ periodicity: "30s", req }); 18 + await cronCompleted(); 19 + } catch (error) { 20 + await cronFailed(); 21 + } 25 22 } 26 23 return NextResponse.json({ success: true }); 27 24 }
+8 -11
apps/web/src/app/api/checker/cron/5m/route.ts
··· 1 - import * as Sentry from "@sentry/nextjs"; 2 1 import type { NextRequest } from "next/server"; 3 2 import { NextResponse } from "next/server"; 4 3 5 4 import { cron, isAuthorizedDomain } from "../_cron"; 5 + import { runSentryCron } from "../_sentry"; 6 6 7 7 export const runtime = "nodejs"; 8 8 // export const preferredRegion = ["auto"]; ··· 12 12 13 13 export async function GET(req: NextRequest) { 14 14 if (isAuthorizedDomain(req.url)) { 15 - const checkInId = Sentry.captureCheckIn({ 16 - monitorSlug: "5-min-cron", 17 - status: "in_progress", 18 - }); 19 - await cron({ periodicity: "5m", req }); 20 - Sentry.captureCheckIn({ 21 - checkInId, 22 - monitorSlug: "5-min-cron", 23 - status: "ok", 24 - }); 15 + const { cronCompleted, cronFailed } = runSentryCron("5-m-cron"); 16 + try { 17 + await cron({ periodicity: "5m", req }); 18 + await cronCompleted(); 19 + } catch (error) { 20 + await cronFailed(); 21 + } 25 22 } 26 23 return NextResponse.json({ success: true }); 27 24 }
+30
apps/web/src/app/api/checker/cron/_sentry.ts
··· 1 + // Props: https://github.com/getsentry/sentry-javascript/issues/9335#issuecomment-1779057528 2 + import { captureCheckIn, flush } from "@sentry/nextjs"; 3 + 4 + export function runSentryCron(monitorSlug: string) { 5 + // 🟡 Notify Sentry your job is running: 6 + const checkInId = captureCheckIn({ 7 + monitorSlug, 8 + status: "in_progress", 9 + }); 10 + return { 11 + cronCompleted: async () => { 12 + // 🟢 Notify Sentry your job has completed successfully: 13 + captureCheckIn({ 14 + checkInId, 15 + monitorSlug, 16 + status: "ok", 17 + }); 18 + return flush(); 19 + }, 20 + cronFailed: async () => { 21 + // 🔴 Notify Sentry your job has failed: 22 + captureCheckIn({ 23 + checkInId, 24 + monitorSlug, 25 + status: "error", 26 + }); 27 + return flush(); 28 + }, 29 + }; 30 + }
+1 -1
apps/web/src/components/monitor-charts/utils.tsx
··· 67 67 */ 68 68 export function renderTimestamp(timestamp: number, _period: Period) { 69 69 const date = new Date(timestamp); 70 - return format(date, "yyyy MMM d, HH:mm"); 70 + return date.toISOString(); 71 71 } 72 72 73 73 export function dataFormatter(number: number) {