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

fix(client): queue status path #21

Merged
merged 1 commit into from
Oct 27, 2023
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
2 changes: 1 addition & 1 deletion libs/client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fal-ai/serverless-client",
"description": "The fal serverless JS/TS client",
"version": "0.4.0",
"version": "0.4.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
16 changes: 5 additions & 11 deletions libs/client/src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export async function subscribe<Input, Output>(
if (options.onEnqueue) {
options.onEnqueue(requestId);
}
const path = options.path ?? '';
return new Promise<Output>((resolve, reject) => {
let timeoutId: ReturnType<typeof setTimeout>;
const pollInterval = options.pollInterval ?? 1000;
Expand All @@ -135,15 +134,14 @@ export async function subscribe<Input, Output>(
const requestStatus = await queue.status(id, {
requestId,
logs: options.logs ?? false,
path,
});
if (options.onQueueUpdate) {
options.onQueueUpdate(requestStatus);
}
if (requestStatus.status === 'COMPLETED') {
clearTimeout(timeoutId);
try {
const result = await queue.result<Output>(id, { requestId, path });
const result = await queue.result<Output>(id, { requestId });
resolve(result);
} catch (error) {
reject(error);
Expand Down Expand Up @@ -194,10 +192,6 @@ type BaseQueueOptions = {
* The unique identifier for the enqueued request.
*/
requestId: string;
/**
* The path to the function, if any. Defaults to ``.
*/
path?: string;
};

type QueueStatusOptions = BaseQueueOptions & {
Expand Down Expand Up @@ -268,23 +262,23 @@ export const queue: Queue = {
},
async status(
id: string,
{ requestId, logs = false, path = '' }: QueueStatusOptions
{ requestId, logs = false }: QueueStatusOptions
): Promise<QueueStatus> {
return run(id, {
method: 'get',
path: `/fal/queue/requests/${requestId}/status${path}`,
path: `/fal/queue/requests/${requestId}/status`,
input: {
logs: logs ? '1' : '0',
},
});
},
async result<Output>(
id: string,
{ requestId, path = '' }: BaseQueueOptions
{ requestId }: BaseQueueOptions
): Promise<Output> {
return run(id, {
method: 'get',
path: `/fal/queue/requests/${requestId}/response${path}`,
path: `/fal/queue/requests/${requestId}/response`,
});
},
subscribe,
Expand Down
Loading