Openstatus www.openstatus.dev

๐Ÿ› Bug monitor length (#1005)

* ๐Ÿ› monitor length

* ๐Ÿ› monitor length

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Thibault Le Ouay
autofix-ci[bot]
and committed by
GitHub
96bbc4b8 05c141f6

+18 -5
+14 -4
apps/web/src/app/api/checker/cron/_cron.ts
··· 80 80 81 81 console.log(`Start cron for ${periodicity}`); 82 82 83 - const monitors = z.array(selectMonitorSchema).parse(result); 83 + const monitors = z.array(selectMonitorSchema).safeParse(result); 84 84 const allResult = []; 85 + if (!monitors.success) { 86 + console.error(`Error while fetching the monitors ${monitors.error.errors}`); 87 + throw new Error("Error while fetching the monitors"); 88 + } 85 89 86 - for (const row of monitors) { 90 + for (const row of monitors.data) { 87 91 const selectedRegions = row.regions.length > 0 ? row.regions : ["ams"]; 88 92 89 93 const result = await db ··· 91 95 .from(monitorStatusTable) 92 96 .where(eq(monitorStatusTable.monitorId, row.id)) 93 97 .all(); 94 - const monitorStatus = z.array(selectMonitorStatusSchema).parse(result); 98 + const monitorStatus = z.array(selectMonitorStatusSchema).safeParse(result); 99 + if (!monitorStatus.success) { 100 + console.error( 101 + `Error while fetching the monitor status ${monitorStatus.error.errors}`, 102 + ); 103 + continue; 104 + } 95 105 96 106 for (const region of selectedRegions) { 97 107 const status = 98 - monitorStatus.find((m) => region === m.region)?.status || "active"; 108 + monitorStatus.data.find((m) => region === m.region)?.status || "active"; 99 109 const response = createCronTask({ 100 110 row, 101 111 timestamp,
+4 -1
packages/db/src/schema/monitors/validation.ts
··· 57 57 .optional(); 58 58 59 59 export const insertMonitorSchema = createInsertSchema(monitor, { 60 - name: z.string().min(1, "Name must be at least 1 character long"), 60 + name: z 61 + .string() 62 + .min(1, "Name must be at least 1 character long") 63 + .max(255, "Name must be at most 255 characters long"), 61 64 periodicity: monitorPeriodicitySchema.default("10m"), 62 65 status: monitorStatusSchema.default("active"), 63 66 regions: z.array(monitorRegionSchema).default([]).optional(),