···11import { Client } from "@upstash/qstash/cloudflare";
22-import type { z } from "zod";
22+import { z } from "zod";
3344import { and, db, eq } from "@openstatus/db";
55import {
66 monitor,
77 monitorsToPages,
88+ RegionEnum,
89 selectMonitorSchema,
910} from "@openstatus/db/src/schema";
1011import { availableRegions } from "@openstatus/tinybird";
···1314import type { payloadSchema } from "../schema";
14151516const periodicityAvailable = selectMonitorSchema.pick({ periodicity: true });
1717+1818+// FIXME: do coerce in zod instead
1919+const currentRegions = z.string().transform((val) => val.split(","));
16201721const DEFAULT_URL = process.env.VERCEL_URL
1822 ? `https://${process.env.VERCEL_URL}`
···4852 .where(eq(monitorsToPages.monitorId, row.id))
4953 .all();
50545151- for (const region of availableRegions) {
5555+ const allMonitorsRegions = currentRegions.parse(row.regions);
5656+ if (allMonitorsRegions.length === 0) {
5257 const payload: z.infer<typeof payloadSchema> = {
5358 workspaceId: String(row.workspaceId),
5459 monitorId: String(row.id),
···59646065 // TODO: fetch + try - catch + retry once
6166 const result = c.publishJSON({
6262- url: `${DEFAULT_URL}/api/checker/regions/${region}`,
6767+ url: `${DEFAULT_URL}/api/checker/regions/random`,
6368 body: payload,
6464- delay: Math.random() * 180,
6969+ delay: Math.random() * 90,
6570 });
6671 allResult.push(result);
7272+ } else {
7373+ for (const region of allMonitorsRegions) {
7474+ const payload: z.infer<typeof payloadSchema> = {
7575+ workspaceId: String(row.workspaceId),
7676+ monitorId: String(row.id),
7777+ url: row.url,
7878+ cronTimestamp: timestamp,
7979+ pageIds: allPages.map((p) => String(p.pageId)),
8080+ };
8181+8282+ const result = c.publishJSON({
8383+ url: `${DEFAULT_URL}/api/checker/regions/${region}`,
8484+ body: payload,
8585+ });
8686+ allResult.push(result);
8787+ }
6788 }
6889 }
6990 // our first legacy monitor
···82103 const result = c.publishJSON({
83104 url: `${DEFAULT_URL}/api/checker/regions/${region}`,
84105 body: payload,
8585- delay: Math.random() * 180,
106106+ delay: Math.random() * 90,
86107 });
87108 allResult.push(result);
88109 }
+1-1
apps/web/src/app/api/checker/regions/_checker.ts
···8686 await monitor(res, result.data, region, latency);
8787 } catch (e) {
8888 // if on the third retry we still get an error, we should report it
8989- if (request.headers.get("Upstash-Retried") === "3") {
8989+ if (request.headers.get("Upstash-Retried") === "2") {
9090 await monitor(
9191 { status: 500, text: () => Promise.resolve(`${e}`) },
9292 result.data,
···2233import * as React from "react";
44import Link from "next/link";
55-import { usePathname, useRouter } from "next/navigation";
55+import { useRouter } from "next/navigation";
66import { MoreVertical } from "lucide-react";
77import type * as z from "zod";
88