REFACTOR ORCA CLIENT LOGIC BUT SOME ISSUES HERE
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { getOrcaClient } from "@_koii/task-manager/extensions";
|
|
||||||
import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper";
|
import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper";
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
import { getRandomNodes } from "../utils/leader";
|
import { getRandomNodes } from "../utils/leader";
|
||||||
@ -10,6 +10,8 @@ import { checkGitHub } from "../utils/githubCheck";
|
|||||||
import { LogLevel } from "@_koii/namespace-wrapper/dist/types";
|
import { LogLevel } from "@_koii/namespace-wrapper/dist/types";
|
||||||
import { actionMessage } from "../utils/constant";
|
import { actionMessage } from "../utils/constant";
|
||||||
import { errorMessage } from "../utils/constant";
|
import { errorMessage } from "../utils/constant";
|
||||||
|
import { handleOrcaClientCreation, handleRequest } from "../utils/orcaHandler/orcaHandler";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
|
||||||
@ -23,7 +25,7 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
// No submission on Round 0 so no need to trigger fetch audit result before round 3
|
// No submission on Round 0 so no need to trigger fetch audit result before round 3
|
||||||
// Changed from 3 to 4 to have more time
|
// Changed from 3 to 4 to have more time
|
||||||
if (roundNumber >= 4) {
|
if (roundNumber >= 4) {
|
||||||
const triggerFetchAuditResult = await fetch(`${middleServerUrl}/api/builder/summarizer/trigger-fetch-audit-result`, {
|
const triggerFetchAuditResult = await fetch(`${middleServerUrl}/api/summarizer/trigger-fetch-audit-result`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@ -34,7 +36,14 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
}
|
}
|
||||||
console.log(`[TASK] EXECUTE TASK FOR ROUND ${roundNumber}`);
|
console.log(`[TASK] EXECUTE TASK FOR ROUND ${roundNumber}`);
|
||||||
try {
|
try {
|
||||||
const orcaClient = await getOrcaClient();
|
let orcaClient;
|
||||||
|
try {
|
||||||
|
orcaClient = await handleOrcaClientCreation();
|
||||||
|
}catch{
|
||||||
|
await namespaceWrapper.logMessage(LogLevel.Error, errorMessage.NO_ORCA_CLIENT, actionMessage.NO_ORCA_CLIENT);
|
||||||
|
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.NO_ORCA_CLIENT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// check if the env variable is valid
|
// check if the env variable is valid
|
||||||
if (!process.env.ANTHROPIC_API_KEY) {
|
if (!process.env.ANTHROPIC_API_KEY) {
|
||||||
await namespaceWrapper.logMessage(LogLevel.Error, errorMessage.ANTHROPIC_API_KEY_INVALID, actionMessage.ANTHROPIC_API_KEY_INVALID);
|
await namespaceWrapper.logMessage(LogLevel.Error, errorMessage.ANTHROPIC_API_KEY_INVALID, actionMessage.ANTHROPIC_API_KEY_INVALID);
|
||||||
@ -63,11 +72,7 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.GITHUB_CHECK_FAILED);
|
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.GITHUB_CHECK_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!orcaClient) {
|
|
||||||
await namespaceWrapper.logMessage(LogLevel.Error, errorMessage.NO_ORCA_CLIENT, actionMessage.NO_ORCA_CLIENT);
|
|
||||||
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.NO_ORCA_CLIENT);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const stakingKeypair = await namespaceWrapper.getSubmitterAccount();
|
const stakingKeypair = await namespaceWrapper.getSubmitterAccount();
|
||||||
if (!stakingKeypair) {
|
if (!stakingKeypair) {
|
||||||
@ -83,13 +88,7 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
const existingIssues = await getExistingIssues();
|
const existingIssues = await getExistingIssues();
|
||||||
const githubUrls = existingIssues.map((issue) => issue.githubUrl);
|
const githubUrls = existingIssues.map((issue) => issue.githubUrl);
|
||||||
try {
|
try {
|
||||||
await orcaClient.podCall(`star/${roundNumber}`, {
|
await handleRequest({orcaClient, route: `star/${roundNumber}`, bodyJSON: { taskId: TASK_ID, round_number: String(roundNumber), github_urls: githubUrls }});
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ taskId: TASK_ID, round_number: String(roundNumber), github_urls: githubUrls }),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.STAR_ISSUE_FAILED);
|
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.STAR_ISSUE_FAILED);
|
||||||
console.error("Error starring issues:", error);
|
console.error("Error starring issues:", error);
|
||||||
@ -110,7 +109,7 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
// const initializedDocumentSummarizeIssues = await getInitializedDocumentSummarizeIssues(existingIssues);
|
// const initializedDocumentSummarizeIssues = await getInitializedDocumentSummarizeIssues(existingIssues);
|
||||||
|
|
||||||
console.log(`[TASK] Making Request to Middle Server with taskId: ${TASK_ID} and round: ${roundNumber}`);
|
console.log(`[TASK] Making Request to Middle Server with taskId: ${TASK_ID} and round: ${roundNumber}`);
|
||||||
const requiredWorkResponse = await fetch(`${middleServerUrl}/api/builder/summarizer/fetch-summarizer-todo`, {
|
const requiredWorkResponse = await fetch(`${middleServerUrl}/api/summarizer/fetch-summarizer-todo`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@ -132,13 +131,7 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
};
|
};
|
||||||
console.log("[TASK] jsonBody: ", jsonBody);
|
console.log("[TASK] jsonBody: ", jsonBody);
|
||||||
try {
|
try {
|
||||||
const repoSummaryResponse = await orcaClient.podCall(`repo_summary/${roundNumber}`, {
|
const repoSummaryResponse = await handleRequest({orcaClient, route: `repo_summary/${roundNumber}`, bodyJSON: jsonBody});
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(jsonBody),
|
|
||||||
});
|
|
||||||
console.log("[TASK] repoSummaryResponse: ", repoSummaryResponse);
|
console.log("[TASK] repoSummaryResponse: ", repoSummaryResponse);
|
||||||
console.log("[TASK] repoSummaryResponse.data.result.data ", repoSummaryResponse.data.result.data);
|
console.log("[TASK] repoSummaryResponse.data.result.data ", repoSummaryResponse.data.result.data);
|
||||||
const payload = {
|
const payload = {
|
||||||
@ -156,7 +149,7 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
stakingKeypair.secretKey,
|
stakingKeypair.secretKey,
|
||||||
);
|
);
|
||||||
console.log("[TASK] signature: ", signature);
|
console.log("[TASK] signature: ", signature);
|
||||||
const addPrToSummarizerTodoResponse = await fetch(`${middleServerUrl}/api/builder/summarizer/add-pr-to-summarizer-todo`, {
|
const addPrToSummarizerTodoResponse = await fetch(`${middleServerUrl}/api/summarizer/add-pr-to-summarizer-todo`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -170,42 +163,10 @@ export async function task(roundNumber: number): Promise<void> {
|
|||||||
}
|
}
|
||||||
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUCCESSFULLY_SUMMARIZED);
|
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUCCESSFULLY_SUMMARIZED);
|
||||||
} else {
|
} else {
|
||||||
// post this summary response to slack` to notify the team
|
|
||||||
// THE HOOK IS ALREADY DISABLED
|
|
||||||
// try{
|
|
||||||
// const slackResponse = await fetch('https://hooks.slack.com/services/', {
|
|
||||||
// method: "POST",
|
|
||||||
// headers: {
|
|
||||||
// "Content-Type": "application/json",
|
|
||||||
// },
|
|
||||||
// body: JSON.stringify({
|
|
||||||
// text: `[TASK] Error summarizing issue:\nStatus: ${repoSummaryResponse.status}\nData: ${JSON.stringify(repoSummaryResponse.data, null, 2)}`
|
|
||||||
// }),
|
|
||||||
// });
|
|
||||||
// console.log("[TASK] slackResponse: ", slackResponse);
|
|
||||||
// }catch(error){
|
|
||||||
// console.error("[TASK] Error posting to slack:", error);
|
|
||||||
// }
|
|
||||||
|
|
||||||
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_FAILED_TO_BE_SUMMARIZED);
|
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_FAILED_TO_BE_SUMMARIZED);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_FAILED_TO_BE_SUMMARIZED);
|
await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_FAILED_TO_BE_SUMMARIZED);
|
||||||
|
|
||||||
// try{
|
|
||||||
// const slackResponse = await fetch('https://hooks.slack.com/services', {
|
|
||||||
// method: "POST",
|
|
||||||
// headers: {
|
|
||||||
// "Content-Type": "application/json",
|
|
||||||
// },
|
|
||||||
// body: JSON.stringify({
|
|
||||||
// text: `[TASK] Error summarizing issue:\n ${JSON.stringify(error)}`
|
|
||||||
// }),
|
|
||||||
// });
|
|
||||||
// console.log("[TASK] slackResponse: ", slackResponse);
|
|
||||||
// }catch(error){
|
|
||||||
// console.error("[TASK] Error posting to slack:", error);
|
|
||||||
// }
|
|
||||||
console.error("[TASK] EXECUTE TASK ERROR:", error);
|
console.error("[TASK] EXECUTE TASK ERROR:", error);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { storeFile } from "../utils/ipfs";
|
import { storeFile } from "../utils/ipfs";
|
||||||
import { getOrcaClient } from "@_koii/task-manager/extensions";
|
import { handleOrcaClientCreation, handleRequest } from "../utils/orcaHandler/orcaHandler";
|
||||||
import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper";
|
import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper";
|
||||||
import { status } from "../utils/constant";
|
import { status } from "../utils/constant";
|
||||||
export async function submission(roundNumber: number) : Promise<string | void> {
|
export async function submission(roundNumber: number) : Promise<string | void> {
|
||||||
@ -13,11 +13,14 @@ export async function submission(roundNumber: number) : Promise<string | void> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("[SUBMISSION] Initializing Orca client...");
|
console.log("[SUBMISSION] Initializing Orca client...");
|
||||||
const orcaClient = await getOrcaClient();
|
let orcaClient;
|
||||||
if (!orcaClient) {
|
try {
|
||||||
|
orcaClient = await handleOrcaClientCreation();
|
||||||
|
}catch{
|
||||||
console.error("[SUBMISSION] Failed to initialize Orca client");
|
console.error("[SUBMISSION] Failed to initialize Orca client");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[SUBMISSION] Orca client initialized successfully");
|
console.log("[SUBMISSION] Orca client initialized successfully");
|
||||||
|
|
||||||
console.log(`[SUBMISSION] Fetching task result for round ${roundNumber}...`);
|
console.log(`[SUBMISSION] Fetching task result for round ${roundNumber}...`);
|
||||||
@ -34,7 +37,7 @@ export async function submission(roundNumber: number) : Promise<string | void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[SUBMISSION] Fetching submission data for round ${roundNumber}...`);
|
console.log(`[SUBMISSION] Fetching submission data for round ${roundNumber}...`);
|
||||||
const result = await orcaClient.podCall(`submission/${roundNumber}`);
|
const result = await handleRequest({orcaClient, route: `submission/${roundNumber}`, bodyJSON: { taskId: TASK_ID, roundNumber }});
|
||||||
let submission;
|
let submission;
|
||||||
|
|
||||||
console.log("[SUBMISSION] Submission result:", result.data);
|
console.log("[SUBMISSION] Submission result:", result.data);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { getOrcaClient } from "@_koii/task-manager/extensions";
|
|
||||||
import { middleServerUrl, status } from "../utils/constant";
|
import { middleServerUrl, status } from "../utils/constant";
|
||||||
import { submissionJSONSignatureDecode } from "../utils/submissionJSONSignatureDecode";
|
import { submissionJSONSignatureDecode } from "../utils/submissionJSONSignatureDecode";
|
||||||
|
import { handleOrcaClientCreation, handleRequest } from "../utils/orcaHandler/orcaHandler";
|
||||||
// import { status } from '../utils/constant'
|
// import { status } from '../utils/constant'
|
||||||
export async function audit(cid: string, roundNumber: number, submitterKey: string): Promise<boolean | void> {
|
export async function audit(cid: string, roundNumber: number, submitterKey: string): Promise<boolean | void> {
|
||||||
/**
|
/**
|
||||||
@ -11,11 +11,13 @@ export async function audit(cid: string, roundNumber: number, submitterKey: stri
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const orcaClient = await getOrcaClient();
|
let orcaClient;
|
||||||
if (!orcaClient) {
|
try {
|
||||||
// await namespaceWrapper.storeSet(`result-${roundNumber}`, status.NO_ORCA_CLIENT);
|
orcaClient = await handleOrcaClientCreation();
|
||||||
|
}catch{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the cid is one of the status
|
// Check if the cid is one of the status
|
||||||
if (Object.values(status).includes(cid)) {
|
if (Object.values(status).includes(cid)) {
|
||||||
// This returns a dummy true
|
// This returns a dummy true
|
||||||
@ -29,7 +31,7 @@ export async function audit(cid: string, roundNumber: number, submitterKey: stri
|
|||||||
console.log(`[AUDIT] ✅ Signature decoded successfully`);
|
console.log(`[AUDIT] ✅ Signature decoded successfully`);
|
||||||
|
|
||||||
console.log(`[AUDIT] Checking summarizer status for submitter ${submitterKey}`);
|
console.log(`[AUDIT] Checking summarizer status for submitter ${submitterKey}`);
|
||||||
const checkSummarizerResponse = await fetch(`${middleServerUrl}/api/builder/summarizer/check-summarizer`, {
|
const checkSummarizerResponse = await fetch(`${middleServerUrl}/api/summarizer/check-summarizer`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@ -53,15 +55,9 @@ export async function audit(cid: string, roundNumber: number, submitterKey: stri
|
|||||||
console.log(`[AUDIT] Sending audit request for submitter: ${submitterKey}`);
|
console.log(`[AUDIT] Sending audit request for submitter: ${submitterKey}`);
|
||||||
console.log(`[AUDIT] Submission data being sent to audit:`, decodeResult);
|
console.log(`[AUDIT] Submission data being sent to audit:`, decodeResult);
|
||||||
|
|
||||||
const result = await orcaClient.podCall(`audit/${roundNumber}`, {
|
const result = await handleRequest({orcaClient, route: `audit/${roundNumber}`, bodyJSON: {
|
||||||
method: "POST",
|
submission: decodeResult,
|
||||||
headers: {
|
}});
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
submission: decodeResult,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`[AUDIT] Raw audit result:`, result);
|
console.log(`[AUDIT] Raw audit result:`, result);
|
||||||
console.log(`[AUDIT] Audit result data type:`, typeof result.data);
|
console.log(`[AUDIT] Audit result data type:`, typeof result.data);
|
||||||
|
@ -2,10 +2,6 @@ import { Submitter, DistributionList } from "@_koii/task-manager";
|
|||||||
import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper";
|
import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper";
|
||||||
import { customReward, status } from "../utils/constant";
|
import { customReward, status } from "../utils/constant";
|
||||||
import { Submission } from "@_koii/namespace-wrapper/dist/types";
|
import { Submission } from "@_koii/namespace-wrapper/dist/types";
|
||||||
import { middleServerUrl } from "../utils/constant";
|
|
||||||
import { getOrcaClient } from "@_koii/task-manager/extensions";
|
|
||||||
import { submissionJSONSignatureDecode } from "../utils/submissionJSONSignatureDecode";
|
|
||||||
import { getRandomNodes } from "../utils/leader";
|
|
||||||
const getSubmissionList = async (roundNumber: number): Promise<Record<string, Submission>> => {
|
const getSubmissionList = async (roundNumber: number): Promise<Record<string, Submission>> => {
|
||||||
const submissionInfo = await namespaceWrapper.getTaskSubmissionInfo(roundNumber);
|
const submissionInfo = await namespaceWrapper.getTaskSubmissionInfo(roundNumber);
|
||||||
return submissionInfo?.submissions[roundNumber] || {};
|
return submissionInfo?.submissions[roundNumber] || {};
|
||||||
|
46
worker/src/utils/orcaHandler/orcaHandler.ts
Normal file
46
worker/src/utils/orcaHandler/orcaHandler.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
|
||||||
|
import { getOrcaClient } from "@_koii/task-manager/extensions";
|
||||||
|
export async function handleOrcaClientCreation(){
|
||||||
|
try {
|
||||||
|
// if (process.env.NODE_ENV !== "development") {
|
||||||
|
// const { getOrcaClient } = await import("@_koii/task-manager/extensions");
|
||||||
|
const orcaClient = await getOrcaClient();
|
||||||
|
if (!orcaClient) {
|
||||||
|
throw new Error("Orca client not found");
|
||||||
|
}
|
||||||
|
return orcaClient;
|
||||||
|
// }else{
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
}catch{
|
||||||
|
throw new Error("Orca client not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export async function handleRequest({orcaClient, route, bodyJSON}:{orcaClient:any, route:string, bodyJSON:any}){
|
||||||
|
// if (process.env.NODE_ENV === "development") {
|
||||||
|
// const response = await fetch(`${process.env.LOCAL_CONTAINER_TEST_URL}/${route}`, {
|
||||||
|
// method: "POST",
|
||||||
|
// headers: {
|
||||||
|
// "Content-Type": "application/json",
|
||||||
|
// },
|
||||||
|
// body: JSON.stringify(bodyJSON),
|
||||||
|
// });
|
||||||
|
// return response;
|
||||||
|
// }else{
|
||||||
|
if (!orcaClient) {
|
||||||
|
throw new Error("Orca client not found");
|
||||||
|
}
|
||||||
|
const response = await orcaClient.podCall(`${route}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(bodyJSON),
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
// }
|
||||||
|
}
|
Reference in New Issue
Block a user