Skip to content

Commit 8081e16

Browse files
committed
移除多余的 taskflow VM 信息查询
1 parent e24cb94 commit 8081e16

3 files changed

Lines changed: 25 additions & 33 deletions

File tree

backend/biz/host/usecase/host.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -479,21 +479,13 @@ func (h *HostUsecase) VMInfo(ctx context.Context, uid uuid.UUID, id string) (*do
479479
return nil, err
480480
}
481481

482-
reportedStatus := taskflow.VirtualMachineStatusUnknown
483-
if info, err := h.taskflow.VirtualMachiner().Info(ctx, taskflow.VirtualMachineInfoReq{
484-
ID: vm.ID,
485-
UserID: vm.UserID.String(),
486-
}); err == nil && info != nil && info.Status != taskflow.VirtualMachineStatusUnknown {
487-
reportedStatus = info.Status
488-
}
489482
dvm := cvt.From(vm, &domain.VirtualMachine{
490483
Status: vmstatus.Resolve(vmstatus.Input{
491-
ReportedStatus: reportedStatus,
492-
Online: vmonline.OnlineMap[vm.ID],
493-
Conditions: vm.Conditions.Conditions,
494-
IsRecycled: vm.IsRecycled,
495-
CreatedAt: vm.CreatedAt,
496-
Now: time.Now(),
484+
Online: vmonline.OnlineMap[vm.ID],
485+
Conditions: vm.Conditions.Conditions,
486+
IsRecycled: vm.IsRecycled,
487+
CreatedAt: vm.CreatedAt,
488+
Now: time.Now(),
497489
}),
498490
})
499491

backend/pkg/vmstatus/status.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,18 @@ import (
1010
const readyTimeout = 3 * time.Minute
1111

1212
type Input struct {
13-
ReportedStatus taskflow.VirtualMachineStatus
14-
Online bool
15-
Conditions []*etypes.Condition
16-
IsRecycled bool
17-
CreatedAt time.Time
18-
Now time.Time
13+
Online bool
14+
Conditions []*etypes.Condition
15+
IsRecycled bool
16+
CreatedAt time.Time
17+
Now time.Time
1918
}
2019

2120
func Resolve(input Input) taskflow.VirtualMachineStatus {
2221
if input.IsRecycled {
2322
return taskflow.VirtualMachineStatusOffline
2423
}
2524

26-
if input.ReportedStatus != "" && input.ReportedStatus != taskflow.VirtualMachineStatusUnknown {
27-
return input.ReportedStatus
28-
}
29-
3025
if input.Online {
3126
return taskflow.VirtualMachineStatusOnline
3227
}

backend/pkg/vmstatus/status_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package vmstatus
22

33
import (
4+
"reflect"
45
"testing"
56
"time"
67

78
etypes "github.com/chaitin/MonkeyCode/backend/ent/types"
89
"github.com/chaitin/MonkeyCode/backend/pkg/taskflow"
910
)
1011

12+
func TestInputDoesNotExposeReportedStatus(t *testing.T) {
13+
if _, ok := reflect.TypeOf(Input{}).FieldByName("ReportedStatus"); ok {
14+
t.Fatal("Input should not expose ReportedStatus")
15+
}
16+
}
17+
1118
func TestResolve(t *testing.T) {
1219
now := time.Date(2026, 4, 15, 12, 0, 0, 0, time.UTC)
1320

@@ -19,29 +26,27 @@ func TestResolve(t *testing.T) {
1926
{
2027
name: "is recycled overrides everything",
2128
input: Input{
22-
ReportedStatus: taskflow.VirtualMachineStatusOnline,
23-
Online: true,
24-
IsRecycled: true,
25-
CreatedAt: now.Add(-10 * time.Minute),
26-
Now: now,
29+
Online: true,
30+
IsRecycled: true,
31+
CreatedAt: now.Add(-10 * time.Minute),
32+
Now: now,
2733
},
2834
want: taskflow.VirtualMachineStatusOffline,
2935
},
3036
{
31-
name: "reported status wins over online and conditions",
37+
name: "online returns online before conditions",
3238
input: Input{
33-
ReportedStatus: taskflow.VirtualMachineStatusHibernated,
34-
Online: true,
39+
Online: true,
3540
Conditions: []*etypes.Condition{
3641
{Type: etypes.ConditionTypeFailed},
3742
},
3843
CreatedAt: now.Add(-10 * time.Minute),
3944
Now: now,
4045
},
41-
want: taskflow.VirtualMachineStatusHibernated,
46+
want: taskflow.VirtualMachineStatusOnline,
4247
},
4348
{
44-
name: "online returns online when no reported status",
49+
name: "online returns online",
4550
input: Input{
4651
Online: true,
4752
CreatedAt: now.Add(-10 * time.Minute),

0 commit comments

Comments
 (0)