Skip to content

Commit

Permalink
feat: introduce priority for subscribe and submit
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Oct 21, 2024
1 parent 83e21ef commit 00b30b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion libs/client/src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "./types";
import { parseEndpointId } from "./utils";

export type QueuePriority = "low" | "normal";
export type QueueStatusSubscriptionOptions = QueueStatusOptions &
Omit<QueueSubscribeOptions, "onEnqueue" | "webhookUrl">;

Expand Down Expand Up @@ -71,6 +72,12 @@ export type QueueSubscribeOptions = {
* @see WebHookResponse
*/
webhookUrl?: string;

/**
* The priority of the request. It defaults to `normal`.
* @see QueuePriority
*/
priority?: QueuePriority;
} & (
| {
mode?: "polling";
Expand Down Expand Up @@ -102,6 +109,12 @@ export type SubmitOptions<Input> = RunOptions<Input> & {
* @see WebHookResponse
*/
webhookUrl?: string;

/**
* The priority of the request. It defaults to `normal`.
* @see QueuePriority
*/
priority?: QueuePriority;
};

type BaseQueueOptions = {
Expand Down Expand Up @@ -216,7 +229,7 @@ export const createQueueClient = ({
endpointId: string,
options: SubmitOptions<Input>,
): Promise<InQueueQueueStatus> {
const { webhookUrl, ...runOptions } = options;
const { webhookUrl, priority, ...runOptions } = options;

Check warning on line 232 in libs/client/src/queue.ts

View workflow job for this annotation

GitHub Actions / build

'priority' is assigned a value but never used
const input = options.input
? await storage.transformInput(options.input)
: undefined;
Expand All @@ -227,6 +240,9 @@ export const createQueueClient = ({
subdomain: "queue",
query: webhookUrl ? { fal_webhook: webhookUrl } : undefined,
}),
headers: {
"x-fal-queue-priority": options.priority ?? "normal",
},
input: input as Input,
config,
});
Expand Down
2 changes: 2 additions & 0 deletions libs/client/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type RequestParams<Input = any> = {
input?: Input;
config: RequiredConfig;
options?: RequestOptions & RequestInit;
headers?: Record<string, string>;
};

export async function dispatchRequest<Input, Output>(
Expand All @@ -39,6 +40,7 @@ export async function dispatchRequest<Input, Output>(
const { method, url, headers } = await requestMiddleware({
method: (params.method ?? options.method ?? "post").toUpperCase(),
url: targetUrl,
headers: params.headers,
});
const authHeader = credentials ? { Authorization: `Key ${credentials}` } : {};
const requestHeaders = {
Expand Down

0 comments on commit 00b30b6

Please sign in to comment.