Skip to content

Commit 666b59b

Browse files
committed
Dtale progress indicator and debugging
1 parent 44c8f92 commit 666b59b

2 files changed

Lines changed: 120 additions & 26 deletions

File tree

‎backend/expressServer.mjs‎

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,43 @@ function parseDtalePort(webServerUrl) {
504504
}
505505
}
506506

507+
function extractDtaleReadyInfo(progressPayload) {
508+
let parsed = progressPayload
509+
if (typeof parsed === "string") {
510+
parsed = cleanGoResponsePayload(parsed)
511+
}
512+
513+
if (parsed && typeof parsed === "object") {
514+
const remotePort = Number(parsed.port) || parseDtalePort(parsed.web_server_url)
515+
return {
516+
parsed,
517+
error: parsed.error || null,
518+
remotePort: Number.isFinite(remotePort) && remotePort > 0 ? remotePort : null,
519+
webServerUrl: parsed.web_server_url || null,
520+
name: parsed.name || null,
521+
snapshot: JSON.stringify(parsed)
522+
}
523+
}
524+
525+
const raw = typeof progressPayload === "string" ? progressPayload : String(progressPayload || "")
526+
const urlMatch = raw.match(/"web_server_url"\s*:\s*"([^"]+)"/)
527+
const portMatch = raw.match(/"port"\s*:\s*(\d+)/)
528+
const nameMatch = raw.match(/"name"\s*:\s*"([^"]+)"/)
529+
const errorMatch = raw.match(/"error"\s*:\s*"([^"]+)"/)
530+
531+
const urlFromRaw = urlMatch ? urlMatch[1] : null
532+
const portFromRaw = portMatch ? Number(portMatch[1]) : parseDtalePort(urlFromRaw)
533+
534+
return {
535+
parsed: null,
536+
error: errorMatch ? errorMatch[1] : null,
537+
remotePort: Number.isFinite(portFromRaw) && portFromRaw > 0 ? portFromRaw : null,
538+
webServerUrl: urlFromRaw,
539+
name: nameMatch ? nameMatch[1] : null,
540+
snapshot: raw
541+
}
542+
}
543+
507544
async function waitForDtaleReady(progressTopic, timeoutMs = 300000) {
508545
const start = Date.now()
509546
let lastProgress = null
@@ -517,40 +554,26 @@ async function waitForDtaleReady(progressTopic, timeoutMs = 300000) {
517554
continue
518555
}
519556

520-
if (typeof progress === "string") {
521-
progress = cleanGoResponsePayload(progress)
557+
const readyInfo = extractDtaleReadyInfo(progress)
558+
if (readyInfo.snapshot) {
559+
lastProgress = readyInfo.snapshot
522560
}
523561

524-
if (progress && typeof progress === "object") {
525-
lastProgress = progress
562+
if (readyInfo.error) {
563+
throw new Error(`D-Tale startup failed: ${readyInfo.error}`)
526564
}
527565

528-
if (progress && typeof progress === "object" && progress.error) {
529-
throw new Error(`D-Tale startup failed: ${progress.error}`)
530-
}
531-
532-
if (progress && progress.web_server_url) {
533-
const remotePort = parseDtalePort(progress.web_server_url)
534-
if (remotePort) {
535-
return {
536-
webServerUrl: progress.web_server_url,
537-
remotePort,
538-
name: progress.name || "D-Tale"
539-
}
540-
}
541-
}
542-
543-
const progressPort = Number(progress && progress.port)
544-
if (Number.isFinite(progressPort) && progressPort > 0) {
566+
if (readyInfo.remotePort) {
567+
const resolvedUrl = readyInfo.webServerUrl || `http://127.0.0.1:${readyInfo.remotePort}/`
545568
return {
546-
webServerUrl: `http://127.0.0.1:${progressPort}/`,
547-
remotePort: progressPort,
548-
name: (progress && progress.name) || "D-Tale"
569+
webServerUrl: resolvedUrl,
570+
remotePort: readyInfo.remotePort,
571+
name: readyInfo.name || "D-Tale"
549572
}
550573
}
551574
await new Promise((resolve) => setTimeout(resolve, 1000))
552575
}
553-
const lastSnapshot = lastProgress ? JSON.stringify(lastProgress) : "no-progress-snapshot"
576+
const lastSnapshot = lastProgress || "no-progress-snapshot"
554577
throw new Error(`Timed out waiting for D-Tale web server to become ready (last progress: ${lastSnapshot})`)
555578
}
556579

@@ -620,6 +643,26 @@ expressApp.post("/exploratory/dtale/start", async (req, res) => {
620643
}
621644
})
622645

646+
expressApp.post("/exploratory/dtale/progress", async (req, res) => {
647+
try {
648+
const routeId = req?.body?.routeId
649+
if (!routeId || typeof routeId !== "string") {
650+
return res.status(400).json({ success: false, error: "routeId is required" })
651+
}
652+
653+
if (!serviceState.go.running || !serviceState.go.port) {
654+
await startGoServer()
655+
}
656+
657+
const progress = await callGoEndpoint(`/exploratory/progress/${routeId}`, {}, { timeoutMs: 10000 })
658+
const parsedProgress = typeof progress === "string" ? cleanGoResponsePayload(progress) : progress
659+
return res.json({ success: true, progress: parsedProgress })
660+
} catch (err) {
661+
console.error("Error getting D-Tale progress:", err)
662+
return res.status(500).json({ success: false, error: err.message })
663+
}
664+
})
665+
623666
expressApp.post("/exploratory/dtale/stop", async (req, res) => {
624667
try {
625668
const body = req.body || {}

‎renderer/components/exploratory/dtale.jsx‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const DTaleProcess = ({ uniqueId, pageId, setError, onDelete }) => {
2929
const { dispatchLayout } = useContext(LayoutModelContext)
3030
const { workspace } = useContext(WorkspaceContext)
3131
const [name, setName] = useState("")
32+
const [currentRouteId, setCurrentRouteId] = useState("")
33+
const [progressPercent, setProgressPercent] = useState(null)
3234

3335
const resolveExpressPort = async (isRemoteMode) => {
3436
const tunnel = getTunnelState()
@@ -93,11 +95,14 @@ const DTaleProcess = ({ uniqueId, pageId, setError, onDelete }) => {
9395
const generateReport = () => {
9496
setIsCalculating(true)
9597
setServerPath("")
98+
setProgressPercent(0)
9699
;(async () => {
97100
try {
98101
await shutdownDTale()
99102
const isRemoteMode = !!workspace?.isRemote
100103
const expressPort = await resolveExpressPort(isRemoteMode)
104+
const routeId = `${uniqueId}/${pageId}-${mainDataset.value.name}`
105+
setCurrentRouteId(routeId)
101106
const response = await window.backend.requestExpress({
102107
method: "post",
103108
port: expressPort,
@@ -113,18 +118,64 @@ const DTaleProcess = ({ uniqueId, pageId, setError, onDelete }) => {
113118
if (!payload.success) {
114119
throw new Error(payload.error || "Failed to start D-Tale")
115120
}
121+
setProgressPercent(100)
116122
const localUrl = await resolveLocalDtaleUrl(uniqueId, payload.remotePort, isRemoteMode)
117123
setServerPath(localUrl)
118124
setName(payload.name || mainDataset.value.name)
119125
} catch (error) {
120126
console.error(error)
127+
setProgressPercent(null)
121128
setError(error?.message || "Failed to start D-Tale")
122129
} finally {
123130
setIsCalculating(false)
131+
setCurrentRouteId("")
124132
}
125133
})()
126134
}
127135

136+
useEffect(() => {
137+
if (!isCalculating || !currentRouteId) {
138+
return
139+
}
140+
141+
let isDisposed = false
142+
143+
const pollProgress = async () => {
144+
try {
145+
const isRemoteMode = !!workspace?.isRemote
146+
const expressPort = await resolveExpressPort(isRemoteMode)
147+
const response = await window.backend.requestExpress({
148+
method: "post",
149+
port: expressPort,
150+
path: "/exploratory/dtale/progress",
151+
body: { routeId: currentRouteId },
152+
timeout: 10000
153+
})
154+
155+
if (isDisposed) return
156+
const payload = response?.data || {}
157+
const nowValue = payload?.progress?.now
158+
const progressNumber = Number(nowValue)
159+
if (Number.isFinite(progressNumber)) {
160+
const bounded = Math.max(0, Math.min(100, Math.round(progressNumber)))
161+
setProgressPercent(bounded)
162+
}
163+
} catch (error) {
164+
if (!isDisposed) {
165+
console.warn("Failed to fetch D-Tale progress:", error)
166+
}
167+
}
168+
}
169+
170+
pollProgress()
171+
const intervalId = setInterval(pollProgress, 1000)
172+
173+
return () => {
174+
isDisposed = true
175+
clearInterval(intervalId)
176+
}
177+
}, [isCalculating, currentRouteId, workspace?.isRemote])
178+
128179
/**
129180
*
130181
* @param {String} urlPath The url path to open
@@ -163,7 +214,7 @@ const DTaleProcess = ({ uniqueId, pageId, setError, onDelete }) => {
163214
/>
164215
</div>
165216
</div>
166-
{isCalculating && <div style={{ fontSize: "0.9rem", opacity: 0.85 }}>Starting D-Tale service...</div>}
217+
{isCalculating && <div style={{ fontSize: "0.9rem", opacity: 0.85 }}>Starting D-Tale service{Number.isFinite(progressPercent) ? ` (${progressPercent}%)` : ""}...</div>}
167218
</>
168219
)
169220
}

0 commit comments

Comments
 (0)