From 56e398d230f8099867208fd9fe3572405e87d99b Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 21 Oct 2024 22:22:24 +0300 Subject: [PATCH] feat: introduce priority for subscribe and submit --- libs/client/src/queue.ts | 18 +++++++++++++++++- libs/client/src/request.ts | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/client/src/queue.ts b/libs/client/src/queue.ts index a6648a1..165230e 100644 --- a/libs/client/src/queue.ts +++ b/libs/client/src/queue.ts @@ -13,6 +13,7 @@ import { } from "./types"; import { parseEndpointId } from "./utils"; +export type QueuePriority = "low" | "normal"; export type QueueStatusSubscriptionOptions = QueueStatusOptions & Omit; @@ -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"; @@ -102,6 +109,12 @@ export type SubmitOptions = RunOptions & { * @see WebHookResponse */ webhookUrl?: string; + + /** + * The priority of the request. It defaults to `normal`. + * @see QueuePriority + */ + priority?: QueuePriority; }; type BaseQueueOptions = { @@ -216,7 +229,7 @@ export const createQueueClient = ({ endpointId: string, options: SubmitOptions, ): Promise { - const { webhookUrl, ...runOptions } = options; + const { webhookUrl, priority, ...runOptions } = options; const input = options.input ? await storage.transformInput(options.input) : undefined; @@ -227,6 +240,9 @@ export const createQueueClient = ({ subdomain: "queue", query: webhookUrl ? { fal_webhook: webhookUrl } : undefined, }), + headers: { + "x-fal-queue-priority": priority ?? "normal", + }, input: input as Input, config, }); diff --git a/libs/client/src/request.ts b/libs/client/src/request.ts index db663c5..03f5cca 100644 --- a/libs/client/src/request.ts +++ b/libs/client/src/request.ts @@ -18,6 +18,7 @@ type RequestParams = { input?: Input; config: RequiredConfig; options?: RequestOptions & RequestInit; + headers?: Record; }; export async function dispatchRequest( @@ -39,6 +40,7 @@ export async function dispatchRequest( 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 = {