From f78fa30923188630b64bfb0e1b0443ee785fa36c Mon Sep 17 00:00:00 2001 From: HermanL02 Date: Tue, 6 May 2025 17:12:58 -0300 Subject: [PATCH] feat: add fail notification --- worker/src/task/5-routes.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/worker/src/task/5-routes.ts b/worker/src/task/5-routes.ts index bee1f53..56c1961 100644 --- a/worker/src/task/5-routes.ts +++ b/worker/src/task/5-routes.ts @@ -63,11 +63,6 @@ export async function routes() { const message = req.body.message; console.log("[TASK] req.body", req.body); try { - if (!success) { - console.error("[TASK] Error summarizing repository:", message); - return; - } - const publicKey = await namespaceWrapper.getMainAccountPubkey(); const stakingKeypair = await namespaceWrapper.getSubmitterAccount(); if (!stakingKeypair) { @@ -75,6 +70,31 @@ export async function routes() { } const stakingKey = stakingKeypair.publicKey.toBase58(); const secretKey = stakingKeypair.secretKey; + if (!success) { + const middleServerPayload = { + taskId: TASK_ID, + action: "add-todo-status", + stakingKey, + } + const middleServerSignature = await namespaceWrapper.payloadSigning(middleServerPayload, secretKey); + console.error("[TASK] Error summarizing repository:", message); + console.log("[TASK] middleServerSignature", middleServerSignature); + + const middleServerResponse = await fetch(`${middleServerUrl}/summarizer/worker/add-todo-status`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ signature: middleServerSignature, stakingKey }), + }); + if (middleServerResponse.status !== 200) { + console.error("[TASK] Error posting to middle server:", middleServerResponse.statusText); + // throw new Error(`Posting to middle server failed: ${middleServerResponse.statusText}`); + } + return; + } + + if (!publicKey) { throw new Error("No public key found");