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

chore: send logs query param to status request as true by default #19

Merged
merged 5 commits into from
Oct 26, 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
3 changes: 2 additions & 1 deletion apps/demo-nextjs-app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ export function Index() {
setLoading(true);
const start = Date.now();
try {
const result: Result = await fal.queue.subscribe('110602490-lora', {
const result: Result = await fal.subscribe('110602490-lora', {
input: {
prompt,
model_name: 'stabilityai/stable-diffusion-xl-base-1.0',
image_size: 'square_hd',
},
pollInterval: 5000, // Default is 1000 (every 1s)
logs: true,
onQueueUpdate(update) {
setElapsedTime(Date.now() - start);
if (
Expand Down
15 changes: 12 additions & 3 deletions libs/client/src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function subscribe<Input, Output>(
const pollInterval = options.pollInterval ?? 1000;
const poll = async () => {
try {
const requestStatus = await queue.status(id, requestId);
const requestStatus = await queue.status(id, requestId, options.logs ?? false);
if (options.onQueueUpdate) {
options.onQueueUpdate(requestStatus);
}
Expand Down Expand Up @@ -176,6 +176,11 @@ type QueueSubscribeOptions = {
* @param status - The current status of the queue.
*/
onQueueUpdate?: (status: QueueStatus) => void;

/**
* If `true`, the response will include the logs for the request.
*/
logs?: boolean;
};

/**
Expand All @@ -197,9 +202,10 @@ interface Queue {
*
* @param id - The ID or URL of the function web endpoint.
* @param requestId - The unique identifier for the enqueued request.
* @param logs - If `true`, the response will include the logs for the request.
* @returns A promise that resolves to the status of the request.
*/
status(id: string, requestId: string): Promise<QueueStatus>;
status(id: string, requestId: string, logs: boolean): Promise<QueueStatus>;

/**
* Retrieves the result of a specific request from the queue.
Expand Down Expand Up @@ -231,10 +237,13 @@ export const queue: Queue = {
): Promise<EnqueueResult> {
return run(id, { ...options, method: 'post', path: '/fal/queue/submit/' });
},
async status(id: string, requestId: string): Promise<QueueStatus> {
async status(id: string, requestId: string, logs = false): Promise<QueueStatus> {
return run(id, {
method: 'get',
path: `/fal/queue/requests/${requestId}/status`,
input: {
logs: logs ? '1' : '0',
},
});
},
async result<Output>(id: string, requestId: string): Promise<Output> {
Expand Down
7 changes: 1 addition & 6 deletions libs/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
request_id: string;
};

// export type QueueStatus = {
// status: "IN_PROGRESS" | "COMPLETED";
// queue: number;
// };

export type RequestLog = {
message: string;
level: 'STDERR' | 'STDOUT' | 'ERROR' | 'INFO' | 'WARN' | 'DEBUG';
Expand All @@ -22,7 +17,7 @@
| {
status: 'IN_PROGRESS' | 'COMPLETED';
response_url: string;
logs: RequestLog[];
logs: null | RequestLog[];
}
| {
status: 'IN_QUEUE';
Expand All @@ -30,7 +25,7 @@
response_url: string;
};

export function isQueueStatus(obj: any): obj is QueueStatus {

Check warning on line 28 in libs/client/src/types.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
return obj && obj.status && obj.response_url;
}

Expand Down
Loading