Openstatus www.openstatus.dev

๐Ÿ” add retry for screenshot service (#849)

authored by

Thibault Le Ouay and committed by
GitHub
5a8c1068 26d46fc0

+24 -13
+2 -2
apps/screenshot-service/fly.toml
··· 22 22 23 23 [http_service.concurrency] 24 24 type = 'requests' 25 - hard_limit = 1000 26 - soft_limit = 500 25 + hard_limit = 4 26 + soft_limit = 2 27 27 28 28 [[http_service.checks]] 29 29 interval = '15s'
+1
apps/server/.env.example
··· 10 10 TWILLIO_ACCOUNT_ID=your_account_id 11 11 12 12 SCREENSHOT_SERVICE_URL=http://your.endpoint 13 + QSTASH_TOKEN=your_token
+1
apps/server/package.json
··· 27 27 "@openstatus/utils": "workspace:*", 28 28 "@t3-oss/env-core": "0.7.1", 29 29 "@unkey/api": "0.16.0", 30 + "@upstash/qstash": "2.1.8", 30 31 "hono": "4.0.0", 31 32 "nanoid": "5.0.2", 32 33 "validator": "13.11.0",
+16 -11
apps/server/src/checker/index.ts
··· 1 1 import { Hono } from "hono"; 2 2 import { z } from "zod"; 3 + import { Client } from "@upstash/qstash"; 3 4 4 5 import { and, db, eq, isNull, schema } from "@openstatus/db"; 5 6 import { incidentTable } from "@openstatus/db/src/schema"; ··· 58 59 and( 59 60 eq(incidentTable.monitorId, Number(monitorId)), 60 61 isNull(incidentTable.resolvedAt), 61 - isNull(incidentTable.acknowledgedAt), 62 - ), 62 + isNull(incidentTable.acknowledgedAt) 63 + ) 63 64 ) 64 65 .get(); 65 66 ··· 99 100 const numberOfRegions = monitor.regions.length; 100 101 101 102 console.log( 102 - `๐Ÿค“ MonitorID ${monitorId} incident current affected ${nbAffectedRegion} total region ${numberOfRegions}`, 103 + `๐Ÿค“ MonitorID ${monitorId} incident current affected ${nbAffectedRegion} total region ${numberOfRegions}` 103 104 ); 104 105 // If the number of affected regions is greater than half of the total region, we trigger the alerting 105 106 // 4 of 6 monitor need to fail to trigger an alerting ··· 113 114 eq(incidentTable.monitorId, Number(monitorId)), 114 115 isNull(incidentTable.resolvedAt), 115 116 isNull(incidentTable.acknowledgedAt), 116 - eq(incidentTable.startedAt, new Date(cronTimestamp)), 117 - ), 117 + eq(incidentTable.startedAt, new Date(cronTimestamp)) 118 + ) 118 119 ) 119 120 .get(); 120 121 ··· 191 192 const numberOfRegions = monitor.regions.length; 192 193 193 194 console.log( 194 - `๐Ÿค“ MonitorId ${monitorId} recovering incident current ${nbAffectedRegion} total region ${numberOfRegions}`, 195 + `๐Ÿค“ MonitorId ${monitorId} recovering incident current ${nbAffectedRegion} total region ${numberOfRegions}` 195 196 ); 196 197 // // If the number of affected regions is greater than half of the total region, we trigger the alerting 197 198 // // 4 of 6 monitor need to fail to trigger an alerting ··· 203 204 and( 204 205 eq(incidentTable.monitorId, Number(monitorId)), 205 206 isNull(incidentTable.resolvedAt), 206 - isNull(incidentTable.acknowledgedAt), 207 - ), 207 + isNull(incidentTable.acknowledgedAt) 208 + ) 208 209 ) 209 210 .get(); 210 211 if (incident) { ··· 258 259 data: z.infer<typeof payload>; 259 260 }) => { 260 261 console.log(` ๐Ÿ“ธ taking screenshot for incident ${data.incidentId}`); 261 - await fetch(env.SCREENSHOT_SERVICE_URL, { 262 + 263 + const client = new Client({ token: env.QSTASH_TOKEN }); 264 + 265 + await client.publishJSON({ 266 + url: env.SCREENSHOT_SERVICE_URL, 262 267 method: "POST", 263 268 headers: { 264 269 "Content-Type": "application/json", 265 270 Authorization: `Basic ${env.CRON_SECRET}`, 266 271 }, 267 - body: JSON.stringify({ 272 + body: { 268 273 url: data.url, 269 274 incidentId: data.incidentId, 270 275 kind: data.kind, 271 - }), 276 + }, 272 277 }); 273 278 };
+1
apps/server/src/env.ts
··· 15 15 JITSU_WRITE_KEY: z.string().optional(), 16 16 JITSU_HOST: z.string().optional(), 17 17 SCREENSHOT_SERVICE_URL: z.string(), 18 + QSTASH_TOKEN: z.string(), 18 19 }, 19 20 20 21 /**
+3
pnpm-lock.yaml
··· 190 190 '@unkey/api': 191 191 specifier: 0.16.0 192 192 version: 0.16.0 193 + '@upstash/qstash': 194 + specifier: 2.1.8 195 + version: 2.1.8 193 196 hono: 194 197 specifier: 4.0.0 195 198 version: 4.0.0