Skip to content

Commit

Permalink
Revert "[Enhancement]: Logs are not fetched in cloud"
Browse files Browse the repository at this point in the history
  • Loading branch information
aakrem authored May 24, 2024
1 parent 2398507 commit 98c3016
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 78 deletions.
79 changes: 11 additions & 68 deletions agenta-web/src/components/Playground/ViewNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ const ViewNavigation: React.FC<Props> = ({
const retriedOnce = useRef(false)
const netWorkError = (error as any)?.code === "ERR_NETWORK"
const [isDrawerOpen, setIsDrawerOpen] = useState(false)
const stopperRef = useRef<Function | null>(null)
const [isDelayed, setIsDelayed] = useState(false)
const [loading, setLoading] = useState(false)
const [isLogsLoading, setIsLogsLoading] = useState(false)

let prevKey = ""
const showNotification = (config: Parameters<typeof notification.open>[0]) => {
Expand All @@ -98,17 +94,8 @@ const ViewNavigation: React.FC<Props> = ({
retriedOnce.current = true
setRetrying(true)
waitForAppToStart({appId, variant, timeout: isDemo() ? 40000 : 6000})
.then((result) => {
if (result) {
stopperRef.current = result.stopper
return result.promise
}
return null
})
.then((promise: any) => {
if (promise) {
return promise.then(() => refetch())
}
.then(() => {
refetch()
})
.catch(() => {
showNotification({
Expand All @@ -119,65 +106,25 @@ const ViewNavigation: React.FC<Props> = ({
})
.finally(() => {
setRetrying(false)
setIsDelayed(false)
})
}

if (isError) {
setLoading(false)
const getLogs = async () => {
try {
setIsLogsLoading(true)
const logs = await fetchVariantLogs(variant.variantId)
setVariantErrorLogs(logs)
} catch (error) {
console.error(error)
showNotification({
type: "error",
message: "Variant logs unreachable",
description: `Unable to fetch variant logs.`,
})
} finally {
setIsLogsLoading(false)
}
const logs = await fetchVariantLogs(variant.variantId)
setVariantErrorLogs(logs)
}
getLogs()
}
}, [netWorkError, isError, variant.variantId])

useEffect(() => {
if (retrying && variantErrorLogs) {
const timeout = setTimeout(() => {
setIsDelayed(true)
}, 6000)
return () => clearTimeout(timeout)
}
}, [retrying, variantErrorLogs])

const handleStopPolling = () => {
setLoading(true)
if (stopperRef.current) {
stopperRef.current()
}
}

if (retrying || (!retriedOnce.current && netWorkError)) {
return (
<>
<div className="grid place-items-center">
<ResultComponent
status={"info"}
title="Waiting for the variant to start"
subtitle={isDelayed ? "This is taking longer than expected" : ""}
spinner={retrying}
/>
{isDelayed && (
<Button loading={loading} onClick={handleStopPolling} type="primary">
Show Logs
</Button>
)}
</div>
</>
<ResultComponent
status={"info"}
title="Waiting for the variant to start"
spinner={retrying}
/>
)
}

Expand Down Expand Up @@ -229,11 +176,7 @@ const ViewNavigation: React.FC<Props> = ({
const apiAddress = `${containerURI}/openapi.json`
return (
<div>
{!error ? null : isLogsLoading || !variantErrorLogs ? (
<div className="grid place-items-center mt-10">
<Spin />
</div>
) : (
{error ? (
<div>
<p>
Error connecting to the variant {variant.variantName}.{" "}
Expand Down Expand Up @@ -294,7 +237,7 @@ const ViewNavigation: React.FC<Props> = ({
</Tooltip>
</Button>
</div>
)}
) : null}
</div>
)
}
Expand Down
12 changes: 2 additions & 10 deletions agenta-web/src/lib/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,25 +580,17 @@ export const waitForAppToStart = async ({
}) => {
const _variant = variant || (await fetchVariants(appId, true))[0]
if (_variant) {
let stopperFunc: Function | null = null

const {stopper, promise} = shortPoll(
() =>
getVariantParametersFromOpenAPI(
appId,
_variant.variantId,
_variant.baseId,
true,
).then(() => {
if (stopperFunc) stopperFunc()
stopper()
}),
).then(() => stopper()),
{delayMs: interval, timeoutMs: timeout},
)

stopperFunc = stopper

return {stopper: stopperFunc, promise}
await promise
}
}

Expand Down

0 comments on commit 98c3016

Please sign in to comment.