Openstatus www.openstatus.dev

๐Ÿ“ improve logging

+10 -15
+10 -15
apps/web/src/app/api/checker/cron/_cron.ts
··· 45 45 periodicity, 46 46 ); 47 47 48 - console.log(`Start cron for ${periodicity}`); 49 48 const timestamp = Date.now(); 50 49 51 - // const ctx = createTRPCContext({ req, serverSideCall: true }); 52 - // // FIXME: we should the proper type 53 - // ctx.auth = { userId: "cron" } as any; 54 - // const caller = edgeRouter.createCaller(ctx); 55 - 56 - // const monitors = await caller.monitor.getMonitorsForPeriodicity({ 57 - // periodicity: periodicity, 58 - // }); 59 50 const result = await db 60 51 .select() 61 52 .from(monitor) 62 53 .where(and(eq(monitor.periodicity, periodicity), eq(monitor.active, true))) 63 54 .all(); 55 + console.log(`Start cron for ${periodicity}`); 56 + 64 57 const monitors = z.array(selectMonitorSchema).parse(result); 65 58 const allResult = []; 66 59 ··· 73 66 .where(eq(monitorStatusTable.monitorId, row.id)) 74 67 .all(); 75 68 const monitorStatus = z.array(selectMonitorStatusSchema).parse(result); 76 - // const monitorStatus = await caller.monitor.getMonitorStatusByMonitorId({ 77 - // monitorId: row.id, 78 - // }); 79 69 80 70 for (const region of selectedRegions) { 81 71 const status = ··· 90 80 }); 91 81 allResult.push(response); 92 82 if (periodicity === "30s") { 93 - console.log("30s cron for", row.id, region, status); 94 83 // we schedule another task in 30s 95 84 const scheduledAt = timestamp + 30 * 1000; 96 85 const response = createCronTask({ ··· 105 94 } 106 95 } 107 96 } 108 - await Promise.allSettled(allResult); 109 97 110 - console.log(`End cron for ${periodicity} with ${allResult.length} jobs`); 98 + const allRequests = await Promise.allSettled(allResult); 99 + 100 + const success = allRequests.filter((r) => r.status === "fulfilled").length; 101 + const failed = allRequests.filter((r) => r.status === "rejected").length; 102 + 103 + console.log( 104 + `End cron for ${periodicity} with ${allResult.length} jobs with ${success} success and ${failed} failed`, 105 + ); 111 106 }; 112 107 // timestamp needs to be in ms 113 108 const createCronTask = async ({