Skip to content

Commit

Permalink
See Promise states for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Rindrics committed Oct 18, 2024
1 parent 52bac99 commit 0e7cb73
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/(playground)/p/[agentId]/beta-proto/graph/server-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,29 @@ import type { Graph } from "./types";
const flushMetricsAndShutdown = async (lf: Langfuse, metricReader: any) => {
return new Promise<void>((resolve, reject) => {
const timeoutId = setTimeout(() => {
console.log("forceFlush: Timeout (Rejected)");
reject(new Error("Metric flush timeout after 20 seconds"));
}, 20000);

console.log("inside waitUntil()-----");
Promise.all([metricReader.forceFlush(), lf.shutdownAsync()])
console.log("forceFlush: Starting (Pending)");

const forceFlushPromise = metricReader.forceFlush();
const shutdownPromise = lf.shutdownAsync();

forceFlushPromise.then(
() => console.log("forceFlush: Completed (Fulfilled)"),
(error) => console.log("forceFlush: Error (Rejected)", error),
);

Promise.all([forceFlushPromise, shutdownPromise])
.then(() => {
clearTimeout(timeoutId);
console.log("All operations completed successfully");
resolve();
})
.catch((error) => {
clearTimeout(timeoutId);
console.log("Error in operations", error);
reject(error);
});
});
Expand Down

0 comments on commit 0e7cb73

Please sign in to comment.