Skip to content

Commit 2d6fce4

Browse files
committed
fix: profile status watcher can get stuck, never updating
if the watcher subprocess exits, we should restart it
1 parent 17e9ada commit 2d6fce4

File tree

1 file changed

+14
-2
lines changed
  • plugins/plugin-codeflare/src/tray/watchers/profile

1 file changed

+14
-2
lines changed

plugins/plugin-codeflare/src/tray/watchers/profile/status.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ export default class ProfileStatusWatcher {
4545
return { label: `Worker nodes: ${this.workerReadiness}` }
4646
}
4747

48+
private async initJobWithDelay(profile: string, delayMillis = 0) {
49+
if (delayMillis) {
50+
// delayed start
51+
await new Promise((resolve) => setTimeout(resolve, delayMillis))
52+
}
53+
return this.initJob(profile)
54+
}
55+
4856
private initJob(profile: string) {
57+
console.error("Watcher start", profile)
4958
const { argv, env } = respawnCommand([
5059
"guide",
5160
"-q",
@@ -72,12 +81,15 @@ export default class ProfileStatusWatcher {
7281
})
7382

7483
job.on("error", () => {
84+
Debug("codeflare")("Watcher error", profile)
7585
this.headReadiness = "error"
7686
this.workerReadiness = "error"
87+
this.initJobWithDelay(profile, 2000) // restart after a delay
7788
})
7889

79-
job.on("close", (exitCode) => {
80-
console.error("Watcher exited with code", exitCode)
90+
job.on("close", async (exitCode) => {
91+
Debug("codeflare")("Watcher exited with code", exitCode)
92+
this.initJobWithDelay(profile, 2000) // restart after a delay
8193
})
8294

8395
job.stdout.on("data", (data) => {

0 commit comments

Comments
 (0)