fix(client): queue status path (#21)
This commit is contained in:
parent
4797a8d4c4
commit
759d58a306
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@fal-ai/serverless-client",
|
"name": "@fal-ai/serverless-client",
|
||||||
"description": "The fal serverless JS/TS client",
|
"description": "The fal serverless JS/TS client",
|
||||||
"version": "0.4.0",
|
"version": "0.4.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@ -126,7 +126,6 @@ export async function subscribe<Input, Output>(
|
|||||||
if (options.onEnqueue) {
|
if (options.onEnqueue) {
|
||||||
options.onEnqueue(requestId);
|
options.onEnqueue(requestId);
|
||||||
}
|
}
|
||||||
const path = options.path ?? '';
|
|
||||||
return new Promise<Output>((resolve, reject) => {
|
return new Promise<Output>((resolve, reject) => {
|
||||||
let timeoutId: ReturnType<typeof setTimeout>;
|
let timeoutId: ReturnType<typeof setTimeout>;
|
||||||
const pollInterval = options.pollInterval ?? 1000;
|
const pollInterval = options.pollInterval ?? 1000;
|
||||||
@ -135,7 +134,6 @@ export async function subscribe<Input, Output>(
|
|||||||
const requestStatus = await queue.status(id, {
|
const requestStatus = await queue.status(id, {
|
||||||
requestId,
|
requestId,
|
||||||
logs: options.logs ?? false,
|
logs: options.logs ?? false,
|
||||||
path,
|
|
||||||
});
|
});
|
||||||
if (options.onQueueUpdate) {
|
if (options.onQueueUpdate) {
|
||||||
options.onQueueUpdate(requestStatus);
|
options.onQueueUpdate(requestStatus);
|
||||||
@ -143,7 +141,7 @@ export async function subscribe<Input, Output>(
|
|||||||
if (requestStatus.status === 'COMPLETED') {
|
if (requestStatus.status === 'COMPLETED') {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
try {
|
try {
|
||||||
const result = await queue.result<Output>(id, { requestId, path });
|
const result = await queue.result<Output>(id, { requestId });
|
||||||
resolve(result);
|
resolve(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
@ -194,10 +192,6 @@ type BaseQueueOptions = {
|
|||||||
* The unique identifier for the enqueued request.
|
* The unique identifier for the enqueued request.
|
||||||
*/
|
*/
|
||||||
requestId: string;
|
requestId: string;
|
||||||
/**
|
|
||||||
* The path to the function, if any. Defaults to ``.
|
|
||||||
*/
|
|
||||||
path?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type QueueStatusOptions = BaseQueueOptions & {
|
type QueueStatusOptions = BaseQueueOptions & {
|
||||||
@ -268,11 +262,11 @@ export const queue: Queue = {
|
|||||||
},
|
},
|
||||||
async status(
|
async status(
|
||||||
id: string,
|
id: string,
|
||||||
{ requestId, logs = false, path = '' }: QueueStatusOptions
|
{ requestId, logs = false }: QueueStatusOptions
|
||||||
): Promise<QueueStatus> {
|
): Promise<QueueStatus> {
|
||||||
return run(id, {
|
return run(id, {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: `/fal/queue/requests/${requestId}/status${path}`,
|
path: `/fal/queue/requests/${requestId}/status`,
|
||||||
input: {
|
input: {
|
||||||
logs: logs ? '1' : '0',
|
logs: logs ? '1' : '0',
|
||||||
},
|
},
|
||||||
@ -280,11 +274,11 @@ export const queue: Queue = {
|
|||||||
},
|
},
|
||||||
async result<Output>(
|
async result<Output>(
|
||||||
id: string,
|
id: string,
|
||||||
{ requestId, path = '' }: BaseQueueOptions
|
{ requestId }: BaseQueueOptions
|
||||||
): Promise<Output> {
|
): Promise<Output> {
|
||||||
return run(id, {
|
return run(id, {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: `/fal/queue/requests/${requestId}/response${path}`,
|
path: `/fal/queue/requests/${requestId}/response`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
subscribe,
|
subscribe,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user