Skip to content

Commit

Permalink
cancel allium query after timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Feb 15, 2025
1 parent 093f2b9 commit 3fe359f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/helpers/allium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ async function retrieveAlliumResults(queryId: string) {
return results.data.data;
}

async function cancelAlliumQuery(queryId: string) {
const response = await axios.post(`https://api.allium.so/api/v1/explorer/query-runs/${queryId}/cancel`, {
headers: HEADERS,
});
return response.data;
}

async function queryAllium(sqlQuery: string) {
const startTime = Date.now();
for (let i = 0; i < 20; i++) {
for (let i = 0; i < 10; i++) {
console.log(`Querying Allium. Attempt ${i}`);
if (!token[sqlQuery]) {
token[sqlQuery] = await startAlliumQuery(sqlQuery);
Expand Down Expand Up @@ -63,6 +70,7 @@ async function queryAllium(sqlQuery: string) {
}
await sleep(20e3);
}
await cancelAlliumQuery(token[sqlQuery]);
console.log(`Query ${sqlQuery} took ${(Date.now() - startTime) / 1000}s`);
throw new Error("Not processed in time");
}
Expand Down

0 comments on commit 3fe359f

Please sign in to comment.