Openstatus www.openstatus.dev

๐Ÿš€ Only go checker (#496)

* ๐Ÿ”ฅ to the moon

* ๐Ÿ”ฅ to the moon

authored by

Thibault Le Ouay and committed by
GitHub
e08af072 9c64fe2d

+37 -37
+19 -19
apps/checker/main.go
··· 132 132 return 133 133 } 134 134 var u InputData 135 - // region := os.Getenv("FLY_REGION") 135 + region := os.Getenv("FLY_REGION") 136 136 137 137 err = json.NewDecoder(r.Body).Decode(&u) 138 138 ··· 152 152 if error != nil { 153 153 sendToTinybirdNew(response) 154 154 if u.Status == "active" { 155 - // updateStatus(UpdateData{ 156 - // MonitorId: u.MonitorId, 157 - // Status: "error", 158 - // Message: error.Error(), 159 - // Region: region, 160 - // }) 155 + updateStatus(UpdateData{ 156 + MonitorId: u.MonitorId, 157 + Status: "error", 158 + Message: error.Error(), 159 + Region: region, 160 + }) 161 161 } 162 162 w.Write([]byte("Ok")) 163 163 w.WriteHeader(200) ··· 168 168 169 169 if response.StatusCode < 200 || response.StatusCode >= 300 { 170 170 // If the status code is not within the 200 range, we update the status to error 171 - // updateStatus(UpdateData{ 172 - // MonitorId: u.MonitorId, 173 - // Status: "error", 174 - // StatusCode: response.StatusCode, 175 - // Region: region, 176 - // }) 171 + updateStatus(UpdateData{ 172 + MonitorId: u.MonitorId, 173 + Status: "error", 174 + StatusCode: response.StatusCode, 175 + Region: region, 176 + }) 177 177 } 178 178 if u.Status == "error" { 179 179 // If the status was error, we update it to active 180 - // updateStatus(UpdateData{ 181 - // MonitorId: u.MonitorId, 182 - // Status: "active", 183 - // Region: region, 184 - // StatusCode: response.StatusCode, 185 - // }) 180 + updateStatus(UpdateData{ 181 + MonitorId: u.MonitorId, 182 + Status: "active", 183 + Region: region, 184 + StatusCode: response.StatusCode, 185 + }) 186 186 } 187 187 188 188 fmt.Printf("โฑ๏ธ End checker for %+v with latency %+d and statusCode %+d", u, response.Latency, response.StatusCode)
+1 -1
apps/server/src/checker/index.ts
··· 119 119 } 120 120 }); 121 121 122 - checkerRoute.post("/statusChange", async (c) => { 122 + checkerRoute.post("/updateStatus", async (c) => { 123 123 const auth = c.req.header("Authorization"); 124 124 if (auth !== `Basic ${env.CRON_SECRET}`) { 125 125 console.error("Unauthorized");
+17 -17
apps/web/src/app/api/checker/cron/_cron.ts
··· 80 80 "active", 81 81 }; 82 82 83 - const task: google.cloud.tasks.v2beta3.ITask = { 84 - httpRequest: { 85 - headers: { 86 - "Content-Type": "application/json", // Set content type to ensure compatibility your application's request parsing 87 - ...(region !== "auto" && { "fly-prefer-region": region }), // Specify the region you want the request to be sent to 88 - Authorization: `Basic ${env.CRON_SECRET}`, 89 - }, 90 - httpMethod: "POST", 91 - url: "https://api.openstatus.dev/checkerV2", 92 - body: Buffer.from(JSON.stringify(payload)).toString("base64"), 93 - }, 94 - }; 83 + // const task: google.cloud.tasks.v2beta3.ITask = { 84 + // httpRequest: { 85 + // headers: { 86 + // "Content-Type": "application/json", // Set content type to ensure compatibility your application's request parsing 87 + // ...(region !== "auto" && { "fly-prefer-region": region }), // Specify the region you want the request to be sent to 88 + // Authorization: `Basic ${env.CRON_SECRET}`, 89 + // }, 90 + // httpMethod: "POST", 91 + // url: "https://api.openstatus.dev/checkerV2", 92 + // body: Buffer.from(JSON.stringify(payload)).toString("base64"), 93 + // }, 94 + // }; 95 95 const newTask: google.cloud.tasks.v2beta3.ITask = { 96 96 httpRequest: { 97 97 headers: { ··· 100 100 Authorization: `Basic ${env.CRON_SECRET}`, 101 101 }, 102 102 httpMethod: "POST", 103 - url: "https://openstatus-checker.fly.dev", 103 + url: "https://openstatus-checker.fly.dev/checker", 104 104 body: Buffer.from(JSON.stringify(payload)).toString("base64"), 105 105 }, 106 106 }; 107 107 108 - const request = { parent: parent, task: task }; 108 + // const request = { parent: parent, task: task }; 109 + // const [response] = await client.createTask(request); 110 + const request = { parent: parent, task: newTask }; 109 111 const [response] = await client.createTask(request); 110 - const requestNew = { parent: parent, task: newTask }; 111 - const [responseNew] = await client.createTask(requestNew); 112 - allResult.push(response, responseNew); 112 + allResult.push(response); 113 113 } 114 114 } 115 115 await Promise.all(allResult);