Skip to content

Commit

Permalink
Merge pull request #19 from fal-ai/matteo/logs-query-param-status
Browse files Browse the repository at this point in the history
chore: send logs query param to status request as true by default
  • Loading branch information
chamini2 authored Oct 26, 2023
2 parents 0e3cb85 + c0d2c94 commit 897fb49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
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 @@ export type EnqueueResult = {
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 @@ export type QueueStatus =
| {
status: 'IN_PROGRESS' | 'COMPLETED';
response_url: string;
logs: RequestLog[];
logs: null | RequestLog[];
}
| {
status: 'IN_QUEUE';
Expand Down

0 comments on commit 897fb49

Please sign in to comment.