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

feat: introduce priority for subscribe and submit #95

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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;
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": 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 @@ -9,15 +9,16 @@
navigator?.userAgent === "Cloudflare-Workers";

type RequestOptions = {
responseHandler?: ResponseHandler<any>;

Check warning on line 12 in libs/client/src/request.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
};

type RequestParams<Input = any> = {

Check warning on line 15 in libs/client/src/request.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
method?: string;
targetUrl: string;
input?: Input;
config: RequiredConfig;
options?: RequestOptions & RequestInit;
headers?: Record<string, string>;
};

export async function dispatchRequest<Input, Output>(
Expand All @@ -39,6 +40,7 @@
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
Loading