From e08af0729779b2c5e0f383c71efe137092d1efc8 Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Date: Sat, 2 Dec 2023 13:29:26 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Only=20go=20checker=20(#496)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔥 to the moon * 🔥 to the moon --- apps/checker/main.go | 38 +++++++++++----------- apps/server/src/checker/index.ts | 2 +- apps/web/src/app/api/checker/cron/_cron.ts | 34 +++++++++---------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/apps/checker/main.go b/apps/checker/main.go index 5be3fbbc8..1f61b4ab4 100644 --- a/apps/checker/main.go +++ b/apps/checker/main.go @@ -132,7 +132,7 @@ func main() { return } var u InputData - // region := os.Getenv("FLY_REGION") + region := os.Getenv("FLY_REGION") err = json.NewDecoder(r.Body).Decode(&u) @@ -152,12 +152,12 @@ func main() { if error != nil { sendToTinybirdNew(response) if u.Status == "active" { - // updateStatus(UpdateData{ - // MonitorId: u.MonitorId, - // Status: "error", - // Message: error.Error(), - // Region: region, - // }) + updateStatus(UpdateData{ + MonitorId: u.MonitorId, + Status: "error", + Message: error.Error(), + Region: region, + }) } w.Write([]byte("Ok")) w.WriteHeader(200) @@ -168,21 +168,21 @@ func main() { if response.StatusCode < 200 || response.StatusCode >= 300 { // If the status code is not within the 200 range, we update the status to error - // updateStatus(UpdateData{ - // MonitorId: u.MonitorId, - // Status: "error", - // StatusCode: response.StatusCode, - // Region: region, - // }) + updateStatus(UpdateData{ + MonitorId: u.MonitorId, + Status: "error", + StatusCode: response.StatusCode, + Region: region, + }) } if u.Status == "error" { // If the status was error, we update it to active - // updateStatus(UpdateData{ - // MonitorId: u.MonitorId, - // Status: "active", - // Region: region, - // StatusCode: response.StatusCode, - // }) + updateStatus(UpdateData{ + MonitorId: u.MonitorId, + Status: "active", + Region: region, + StatusCode: response.StatusCode, + }) } fmt.Printf("⏱️ End checker for %+v with latency %+d and statusCode %+d", u, response.Latency, response.StatusCode) diff --git a/apps/server/src/checker/index.ts b/apps/server/src/checker/index.ts index 7f821d1c2..af3d50c86 100644 --- a/apps/server/src/checker/index.ts +++ b/apps/server/src/checker/index.ts @@ -119,7 +119,7 @@ checkerRoute.post("/checkerV2", async (c) => { } }); -checkerRoute.post("/statusChange", async (c) => { +checkerRoute.post("/updateStatus", async (c) => { const auth = c.req.header("Authorization"); if (auth !== `Basic ${env.CRON_SECRET}`) { console.error("Unauthorized"); diff --git a/apps/web/src/app/api/checker/cron/_cron.ts b/apps/web/src/app/api/checker/cron/_cron.ts index ebe0b32fe..6222c18a5 100644 --- a/apps/web/src/app/api/checker/cron/_cron.ts +++ b/apps/web/src/app/api/checker/cron/_cron.ts @@ -80,18 +80,18 @@ export const cron = async ({ "active", }; - const task: google.cloud.tasks.v2beta3.ITask = { - httpRequest: { - headers: { - "Content-Type": "application/json", // Set content type to ensure compatibility your application's request parsing - ...(region !== "auto" && { "fly-prefer-region": region }), // Specify the region you want the request to be sent to - Authorization: `Basic ${env.CRON_SECRET}`, - }, - httpMethod: "POST", - url: "https://api.openstatus.dev/checkerV2", - body: Buffer.from(JSON.stringify(payload)).toString("base64"), - }, - }; + // const task: google.cloud.tasks.v2beta3.ITask = { + // httpRequest: { + // headers: { + // "Content-Type": "application/json", // Set content type to ensure compatibility your application's request parsing + // ...(region !== "auto" && { "fly-prefer-region": region }), // Specify the region you want the request to be sent to + // Authorization: `Basic ${env.CRON_SECRET}`, + // }, + // httpMethod: "POST", + // url: "https://api.openstatus.dev/checkerV2", + // body: Buffer.from(JSON.stringify(payload)).toString("base64"), + // }, + // }; const newTask: google.cloud.tasks.v2beta3.ITask = { httpRequest: { headers: { @@ -100,16 +100,16 @@ export const cron = async ({ Authorization: `Basic ${env.CRON_SECRET}`, }, httpMethod: "POST", - url: "https://openstatus-checker.fly.dev", + url: "https://openstatus-checker.fly.dev/checker", body: Buffer.from(JSON.stringify(payload)).toString("base64"), }, }; - const request = { parent: parent, task: task }; + // const request = { parent: parent, task: task }; + // const [response] = await client.createTask(request); + const request = { parent: parent, task: newTask }; const [response] = await client.createTask(request); - const requestNew = { parent: parent, task: newTask }; - const [responseNew] = await client.createTask(requestNew); - allResult.push(response, responseNew); + allResult.push(response); } } await Promise.all(allResult); -- 2.54.0