From 0e7cb739d91daee65b369ca8aba0969582c1b234 Mon Sep 17 00:00:00 2001 From: Akira Hayashi Date: Fri, 18 Oct 2024 20:05:19 +0900 Subject: [PATCH] See Promise states for debugging --- .../[agentId]/beta-proto/graph/server-actions.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/(playground)/p/[agentId]/beta-proto/graph/server-actions.ts b/app/(playground)/p/[agentId]/beta-proto/graph/server-actions.ts index 534b8db99..5e3b152e6 100644 --- a/app/(playground)/p/[agentId]/beta-proto/graph/server-actions.ts +++ b/app/(playground)/p/[agentId]/beta-proto/graph/server-actions.ts @@ -24,17 +24,29 @@ import type { Graph } from "./types"; const flushMetricsAndShutdown = async (lf: Langfuse, metricReader: any) => { return new Promise((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); }); });