Openstatus www.openstatus.dev

improve error handling (#1214)

authored by

Thibault Le Ouay and committed by
GitHub
7b1409f8 6bf8d47e

+32 -4
+32 -4
apps/workflows/src/checker/index.ts
··· 96 96 if (affectedRegion.count >= numberOfRegions / 2 || numberOfRegions === 1) { 97 97 switch (status) { 98 98 case "active": { 99 + 100 + if(monitor.status!== 'active') { 101 + await db 102 + .update(schema.monitor) 103 + .set({ status: "active" }) 104 + .where(eq(schema.monitor.id, monitor.id)); 105 + } 106 + 99 107 const incident = await db 100 108 .select() 101 109 .from(incidentTable) ··· 127 135 .where(eq(incidentTable.id, incident.id)) 128 136 .run(); 129 137 130 - await db 131 - .update(schema.monitor) 132 - .set({ status: "active" }) 133 - .where(eq(schema.monitor.id, monitor.id)); 138 + 134 139 135 140 await triggerNotifications({ 136 141 monitorId, ··· 181 186 }); 182 187 break; 183 188 case "error": 189 + 190 + if(monitor.status !== 'error') { 191 + await db 192 + .update(schema.monitor) 193 + .set({ status: "error" }) 194 + .where(eq(schema.monitor.id, monitor.id)); 195 + 196 + } 184 197 try { 198 + const incident = await db 199 + .select() 200 + .from(incidentTable) 201 + .where( 202 + and( 203 + eq(incidentTable.monitorId, Number(monitorId)), 204 + isNull(incidentTable.resolvedAt), 205 + isNull(incidentTable.acknowledgedAt), 206 + ), 207 + ) 208 + .get(); 209 + if(incident) { 210 + console.log('we are already in incident') 211 + break; 212 + } 185 213 const newIncident = await db 186 214 .insert(incidentTable) 187 215 .values({