Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Optional Large Tier Execution Performance #27

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/api/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
import log from "loglevel";
import { logPrefix } from "../utils";
import { Router } from "./router";
import { ExecutionPerformance } from "../types/requestPayload";

// This class implements all the routes defined in the Dune API Docs: https://dune.com/docs/api/
export class ExecutionClient extends Router {
async executeQuery(
queryID: number,
parameters?: QueryParameter[],
performance?: ExecutionPerformance,
): Promise<ExecutionResponse> {
const response = await this._post<ExecutionResponse>(`query/${queryID}/execute`, {
query_parameters: parameters ? parameters : [],
performance: performance ? performance : ExecutionPerformance.Medium,
});
log.debug(logPrefix, `execute response ${JSON.stringify(response)}`);
return response as ExecutionResponse;
Expand Down
8 changes: 7 additions & 1 deletion src/api/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import log from "loglevel";
import { logPrefix } from "../utils";
import { ExecutionClient } from "./execution";
import { POLL_FREQUENCY_SECONDS, THREE_MONTHS_IN_HOURS } from "../constants";
import { ExecutionPerformance } from "../types/requestPayload";

const TERMINAL_STATES = [
ExecutionState.CANCELLED,
Expand All @@ -16,14 +17,19 @@ export class ExtendedClient extends ExecutionClient {
queryID: number,
parameters?: QueryParameter[],
pingFrequency: number = POLL_FREQUENCY_SECONDS,
performance?: ExecutionPerformance,
): Promise<ResultsResponse> {
log.info(
logPrefix,
`refreshing query https://dune.com/queries/${queryID} with parameters ${JSON.stringify(
parameters,
)}`,
);
const { execution_id: jobID } = await this.execute(queryID, parameters);
const { execution_id: jobID } = await this.executeQuery(
queryID,
parameters,
performance,
);
let { state } = await this.getExecutionStatus(jobID);
while (!TERMINAL_STATES.includes(state)) {
log.info(
Expand Down
6 changes: 1 addition & 5 deletions src/api/query.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Assuming the existence of these imports based on your Python code
import { Router } from "./router";
import {
DuneQuery,
QueryParameter,
CreateQueryResponse,
} from "../types";
import { DuneQuery, QueryParameter, CreateQueryResponse } from "../types";
import { CreateQueryPayload, UpdateQueryPayload } from "../types/requestPayload";

export class QueryAPI extends Router {
Expand Down
5 changes: 1 addition & 4 deletions src/api/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { DuneError } from "../types";
import fetch from "cross-fetch";
import log from "loglevel";
import { logPrefix } from "../utils";
import {
RequestPayload,
payloadJSON,
} from "../types/requestPayload";
import { RequestPayload, payloadJSON } from "../types/requestPayload";

const BASE_URL = "https://api.dune.com/api/v1";

Expand Down
6 changes: 6 additions & 0 deletions src/types/requestPayload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { QueryParameter } from "./queryParameter";

export enum ExecutionPerformance {
Medium = "medium",
Large = "large",
}

export type RequestPayload =
| ExecuteQueryPayload
| UpdateQueryPayload
Expand All @@ -24,6 +29,7 @@ export function payloadJSON(payload?: RequestPayload): string {

export interface ExecuteQueryPayload {
query_parameters?: QueryParameter[];
performance: string;
}

export interface UpdateQueryPayload {
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
QueryAPI,
} from "../../src/";
import log from "loglevel";
import { ExecutionPerformance } from "../../src/types/requestPayload";

const { DUNE_API_KEY } = process.env;
const apiKey: string = DUNE_API_KEY ? DUNE_API_KEY : "No API Key";
Expand Down Expand Up @@ -75,6 +76,16 @@ describe("DuneClient: native routes", () => {
expect(execution.execution_id).is.not.null;
});

it("execute with Large tier performance", async () => {
const client = new DuneClient(apiKey);
const execution = await client.executeQuery(
1215383,
undefined,
ExecutionPerformance.Large,
);
expect(execution.execution_id).is.not.null;
});

it("returns expected results on cancelled query exection", async () => {
const client = new DuneClient(apiKey);
// Execute and check state
Expand Down