fix: restore desired media paths on startup (#54)
This commit is contained in:
@@ -24,6 +24,32 @@ func NewService(store Store, process mediamtx.Process, controller mediamtx.Contr
|
|||||||
return &Service{store: store, process: process, controller: controller, profile: admission.VerifiedProfile, credential: device.ReadRTSPCredential, now: time.Now}
|
return &Service{store: store, process: process, controller: controller, profile: admission.VerifiedProfile, credential: device.ReadRTSPCredential, now: time.Now}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore recreates desired routes after MediaMTX starts with its base config.
|
||||||
|
// Individual route failures are persisted as safe business states and do not
|
||||||
|
// prevent the Sense management plane from starting.
|
||||||
|
func (s *Service) Restore(ctx context.Context) error {
|
||||||
|
items, err := s.store.List(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, route := range items {
|
||||||
|
if route.Desired != "running" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, reconcileErr := s.Reconcile(ctx, identity.Principal{}, route.ID); reconcileErr != nil {
|
||||||
|
route.Actual = "apply_failed"
|
||||||
|
route.Detail = "媒体路径恢复失败,请检查视频服务"
|
||||||
|
route.Readers = 0
|
||||||
|
route.Version++
|
||||||
|
route.UpdatedAt = s.now().UTC()
|
||||||
|
if saveErr := s.store.Save(ctx, route); saveErr != nil {
|
||||||
|
return saveErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) ConfigureProfiles(ctx context.Context, actor identity.Principal, result admission.Result) admission.MediaOutcome {
|
func (s *Service) ConfigureProfiles(ctx context.Context, actor identity.Principal, result admission.Result) admission.MediaOutcome {
|
||||||
configured := 0
|
configured := 0
|
||||||
ready := 0
|
ready := 0
|
||||||
@@ -108,6 +134,10 @@ func (s *Service) Reconcile(ctx context.Context, actor identity.Principal, id st
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
route.Actual = "unconverged"
|
route.Actual = "unconverged"
|
||||||
route.Detail = "尚未取得媒体状态"
|
route.Detail = "尚未取得媒体状态"
|
||||||
|
} else if !status.Exists {
|
||||||
|
route.Actual = "apply_failed"
|
||||||
|
route.Detail = "媒体路径不存在,请重新对账"
|
||||||
|
route.Readers = 0
|
||||||
} else if status.Ready {
|
} else if status.Ready {
|
||||||
route.Actual = "ready"
|
route.Actual = "ready"
|
||||||
route.Detail = "上游拉流正常"
|
route.Detail = "上游拉流正常"
|
||||||
@@ -142,7 +172,10 @@ func (s *Service) Refresh(ctx context.Context, id string) (Route, error) {
|
|||||||
}
|
}
|
||||||
actual := "waiting"
|
actual := "waiting"
|
||||||
detail := "等待播放器连接并按需拉流"
|
detail := "等待播放器连接并按需拉流"
|
||||||
if status.Ready {
|
if !status.Exists {
|
||||||
|
actual = "apply_failed"
|
||||||
|
detail = "媒体路径不存在,请重新对账"
|
||||||
|
} else if status.Ready {
|
||||||
actual = "ready"
|
actual = "ready"
|
||||||
detail = "上游拉流正常"
|
detail = "上游拉流正常"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user