@@ -34,7 +34,7 @@ type InternalHostHandler struct {
3434 teamRepo domain.TeamHostRepo
3535 redis * redis.Client
3636 cache * cache.Cache
37- vmLifecycle * lifecycle.Manager [string , lifecycle. VMState , lifecycle.VMMetadata ]
37+ taskLifecycle * lifecycle.Manager [uuid. UUID , consts. TaskStatus , lifecycle.TaskMetadata ]
3838 hostUsecase domain.HostUsecase
3939 taskConns * ws.TaskConn
4040 projectUsecase domain.ProjectUsecase
@@ -50,7 +50,6 @@ func NewInternalHostHandler(i *do.Injector) (*InternalHostHandler, error) {
5050 teamRepo : do.MustInvoke [domain.TeamHostRepo ](i ),
5151 redis : do.MustInvoke [* redis.Client ](i ),
5252 cache : cache .New (15 * time .Minute , 10 * time .Minute ),
53- vmLifecycle : do.MustInvoke [* lifecycle.Manager [string , lifecycle.VMState , lifecycle.VMMetadata ]](i ),
5453 hostUsecase : do.MustInvoke [domain.HostUsecase ](i ),
5554 taskConns : do.MustInvoke [* ws.TaskConn ](i ),
5655 projectUsecase : do.MustInvoke [domain.ProjectUsecase ](i ),
@@ -344,12 +343,11 @@ func (h *InternalHostHandler) VmReady(c *web.Context, req taskflow.VirtualMachin
344343 continue
345344 }
346345
347- if err := h .vmLifecycle .Transition (c .Request ().Context (), vm .ID , lifecycle .VMStateRunning , lifecycle.VMMetadata {
348- VMID : vm .ID ,
349- TaskID : & t .ID ,
346+ if err := h .taskLifecycle .Transition (c .Request ().Context (), t .ID , consts .TaskStatusProcessing , lifecycle.TaskMetadata {
347+ TaskID : t .ID ,
350348 UserID : t .UserID ,
351349 }); err != nil {
352- h .logger .With ("task" , t , "error" , err ).ErrorContext (c .Request ().Context (), "failed to transition vm to running " )
350+ h .logger .With ("task" , t , "error" , err ).ErrorContext (c .Request ().Context (), "failed to transition task to processing " )
353351 }
354352 }
355353
@@ -375,19 +373,18 @@ func (h *InternalHostHandler) VmConditions(c *web.Context, req taskflow.VirtualM
375373 return err
376374 }
377375
378- for _ , task := range vm .Edges .Tasks {
376+ if ts := vm .Edges .Tasks ; len (ts ) > 0 {
377+ t := ts [0 ]
379378 for _ , cond := range req .Conditions {
380- if cond .Type != string (etypes .ConditionTypeFailed ) {
381- continue
382- }
383- if err := h .vmLifecycle .Transition (c .Request ().Context (), vm .ID , lifecycle .VMStateFailed , lifecycle.VMMetadata {
384- VMID : vm .ID ,
385- TaskID : & task .ID ,
386- UserID : task .UserID ,
387- }); err != nil {
388- h .logger .With ("task" , task , "error" , err ).ErrorContext (c .Request ().Context (), "failed to transition vm to failed" )
379+ if cond .Type == string (etypes .ConditionTypeFailed ) {
380+ if err := h .taskLifecycle .Transition (c .Request ().Context (), t .ID , consts .TaskStatusError , lifecycle.TaskMetadata {
381+ TaskID : t .ID ,
382+ UserID : t .UserID ,
383+ }); err != nil {
384+ h .logger .With ("task" , t , "error" , err ).ErrorContext (c .Request ().Context (), "failed to transition task to processing" )
385+ }
386+ break
389387 }
390- break
391388 }
392389 }
393390
0 commit comments