Skip to content

Commit ac8dc25

Browse files
authored
fix block controller status (add version) (#1430)
1 parent f858d3b commit ac8dc25

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

frontend/app/view/term/term.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,18 @@ class TermViewModel implements ViewModel {
311311
}
312312

313313
updateShellProcStatus(fullStatus: BlockControllerRuntimeStatus) {
314-
globalStore.set(this.shellProcFullStatus, fullStatus);
315-
const status = fullStatus?.shellprocstatus ?? "init";
316-
if (status == "running") {
317-
this.termRef.current?.setIsRunning?.(true);
318-
} else {
319-
this.termRef.current?.setIsRunning?.(false);
314+
if (fullStatus == null) {
315+
return;
316+
}
317+
const curStatus = globalStore.get(this.shellProcFullStatus);
318+
if (curStatus == null || curStatus.version < fullStatus.version) {
319+
globalStore.set(this.shellProcFullStatus, fullStatus);
320+
const status = fullStatus?.shellprocstatus ?? "init";
321+
if (status == "running") {
322+
this.termRef.current?.setIsRunning?.(true);
323+
} else {
324+
this.termRef.current?.setIsRunning?.(false);
325+
}
320326
}
321327
}
322328

frontend/types/gotypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ declare global {
5656
// blockcontroller.BlockControllerRuntimeStatus
5757
type BlockControllerRuntimeStatus = {
5858
blockid: string;
59+
version: number;
5960
shellprocstatus?: string;
6061
shellprocconnname?: string;
6162
shellprocexitcode: number;

pkg/blockcontroller/blockcontroller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ type BlockController struct {
7979
ShellProcStatus string
8080
ShellProcExitCode int
8181
RunLock *atomic.Bool
82+
StatusVersion int
8283
}
8384

8485
type BlockControllerRuntimeStatus struct {
8586
BlockId string `json:"blockid"`
87+
Version int `json:"version"`
8688
ShellProcStatus string `json:"shellprocstatus,omitempty"`
8789
ShellProcConnName string `json:"shellprocconnname,omitempty"`
8890
ShellProcExitCode int `json:"shellprocexitcode"`
@@ -97,6 +99,8 @@ func (bc *BlockController) WithLock(f func()) {
9799
func (bc *BlockController) GetRuntimeStatus() *BlockControllerRuntimeStatus {
98100
var rtn BlockControllerRuntimeStatus
99101
bc.WithLock(func() {
102+
bc.StatusVersion++
103+
rtn.Version = bc.StatusVersion
100104
rtn.BlockId = bc.BlockId
101105
rtn.ShellProcStatus = bc.ShellProcStatus
102106
if bc.ShellProc != nil {

0 commit comments

Comments
 (0)