Openstatus www.openstatus.dev
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve retry (#390)

* 🥅 retry

* 🥅 retry

* ✈️ all regions by defualt

authored by

Thibault Le Ouay and committed by
GitHub
67280335 79f9a1d6

+45 -38
+18
apps/server/log/fly.toml
··· 1 + # fly.toml app configuration file generated for openstatus-log on 2023-10-19T00:44:54+02:00 2 + # 3 + # See https://fly.io/docs/reference/configuration/ for information about how to use this file. 4 + # 5 + 6 + app = "openstatus-log" 7 + primary_region = "ams" 8 + 9 + [build] 10 + image = "ghcr.io/superfly/fly-log-shipper:latest" 11 + 12 + [http_service] 13 + internal_port = 8686 14 + force_https = true 15 + auto_stop_machines = true 16 + auto_start_machines = true 17 + min_machines_running = 1 18 + processes = ["app"]
+21 -6
apps/server/src/checker/checker.ts
··· 49 49 }); 50 50 } 51 51 } else { 52 - console.log(`error for ${data.url} with status ${res.status}`); 53 - if (data?.status === "active") { 54 - await updateMonitorStatus({ 55 - monitorId: data.monitorId, 56 - status: "error", 57 - }); 52 + console.log(`first retry for ${data.url} with status ${res.status}`); 53 + const startTime = Date.now(); 54 + const retry = await ping(data); 55 + const endTime = Date.now(); 56 + const latency = endTime - startTime; 57 + if (retry.ok) { 58 + await monitor({ monitorInfo: data, latency, statusCode: res.status }); 59 + if (data?.status === "error") { 60 + await updateMonitorStatus({ 61 + monitorId: data.monitorId, 62 + status: "active", 63 + }); 64 + } 65 + } else { 66 + console.log(`error for ${data.url} with status ${res.status}`); 67 + if (data?.status === "active") { 68 + await updateMonitorStatus({ 69 + monitorId: data.monitorId, 70 + status: "error", 71 + }); 72 + } 58 73 } 59 74 } 60 75 };
+6 -32
apps/web/src/app/api/checker/cron/_cron.ts
··· 48 48 monitorId: row.id, 49 49 }); 50 50 51 - if (row.regions.length === 0 || row.regions.includes("auto")) { 51 + for (const region of flyRegions) { 52 52 const payload: z.infer<typeof payloadSchema> = { 53 53 workspaceId: String(row.workspaceId), 54 - method: row.method || "GET", 55 54 monitorId: String(row.id), 56 55 url: row.url, 57 - headers: row.headers, 58 - body: row.body, 56 + method: row.method || "GET", 59 57 cronTimestamp: timestamp, 60 - status: row.status, 58 + body: row.body, 59 + headers: row.headers, 61 60 pageIds: allPages.map((p) => String(p.pageId)), 61 + status: row.status, 62 62 }; 63 63 64 - // TODO: fetch + try - catch + retry once 65 64 const result = c.publishJSON({ 66 65 url: `https://api.openstatus.dev/checker`, 67 66 body: payload, 68 67 delay: Math.random() * 90, 69 68 headers: { 70 - "Upstash-Forward-fly-prefer-region": "ams", 69 + "Upstash-Forward-fly-prefer-region": region, 71 70 }, 72 71 }); 73 72 allResult.push(result); 74 - } else { 75 - const regions = row.regions; 76 - for (const region of regions) { 77 - const payload: z.infer<typeof payloadSchema> = { 78 - workspaceId: String(row.workspaceId), 79 - monitorId: String(row.id), 80 - url: row.url, 81 - method: row.method || "GET", 82 - cronTimestamp: timestamp, 83 - body: row.body, 84 - headers: row.headers, 85 - pageIds: allPages.map((p) => String(p.pageId)), 86 - status: row.status, 87 - }; 88 - 89 - const result = c.publishJSON({ 90 - url: `https://api.openstatus.dev/checker`, 91 - body: payload, 92 - delay: Math.random() * 90, 93 - headers: { 94 - "Upstash-Forward-fly-prefer-region": region, 95 - }, 96 - }); 97 - allResult.push(result); 98 - } 99 73 } 100 74 } 101 75 // our first legacy monitor