@@ -230,8 +230,8 @@ return nil
230230
231231 // 通过 hook 获取关联的 TaskID(内部项目注入时生效)
232232 taskID := uuid .Nil
233- if h . hook != nil {
234- taskID = h . hook . OnAgentAuth ( ctx , vm .ID )
233+ if len ( vm . Edges . Tasks ) > 0 {
234+ taskID = vm . Edges . Tasks [ 0 ] .ID
235235 }
236236
237237 return & taskflow.Token {
@@ -347,6 +347,15 @@ func (h *InternalHostHandler) VmReady(c *web.Context, req taskflow.VirtualMachin
347347 h .logger .With ("task" , t , "error" , err ).ErrorContext (c .Request ().Context (), "failed to transition task to processing" )
348348 }
349349 }
350+
351+ go func () {
352+ ctx , cancel := context .WithTimeout (context .Background (), 15 * time .Second )
353+ defer cancel ()
354+ if err := h .hostUsecase .RefreshIdleTimers (ctx , vm .ID ); err != nil {
355+ h .logger .With ("error" , err ).ErrorContext (ctx , "failed to refresh idel timers" )
356+ }
357+ }()
358+
350359 }
351360
352361 return c .Success (nil )
@@ -421,17 +430,12 @@ type VMActivityReq struct {
421430
422431// VMActivity VM 活动回调,用于刷新空闲计时器
423432func (h * InternalHostHandler ) VMActivity (c * web.Context , req VMActivityReq ) error {
424- vm , err := h .repo .GetVirtualMachine (c .Request ().Context (), req .VMID )
425- if err != nil {
426- h .logger .ErrorContext (c .Request ().Context (), "vm activity: vm not found" , "vmID" , req .VMID , "error" , err )
427- return err
428- }
429-
430- payload := & domain.VmIdleInfo {
431- UID : vm .UserID ,
432- VmID : vm .ID ,
433- HostID : vm .HostID ,
434- EnvID : vm .EnvironmentID ,
435- }
436- return h .hostUsecase .RefreshIdleTimers (c .Request ().Context (), req .VMID , payload )
433+ go func () {
434+ ctx , cancel := context .WithTimeout (context .Background (), 15 * time .Second )
435+ defer cancel ()
436+ if err := h .hostUsecase .RefreshIdleTimers (ctx , req .VMID ); err != nil {
437+ h .logger .With ("error" , err ).ErrorContext (ctx , "failed to refresh idel timers" )
438+ }
439+ }()
440+ return c .Success (nil )
437441}
0 commit comments