Skip to content

Commit

Permalink
separate out app and container history sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
sudiptob2 committed Nov 6, 2024
1 parent 8912e43 commit b91b2da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions internal/yunikorn/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ func (s *Service) Run(ctx context.Context) error {
if err := s.syncNodes(ctx, fullState.Nodes); err != nil {
return fmt.Errorf("error syncing nodes: %v", err)
}
if err := s.syncHistory(ctx, fullState.AppHistory, fullState.ContainerHistory); err != nil {
return fmt.Errorf("error syncing app and container history: %v", err)
if err := s.syncAppHistory(ctx, fullState.AppHistory); err != nil {
return fmt.Errorf("error syncing app history: %v", err)
}
if err := s.syncContainerHistory(ctx, fullState.ContainerHistory); err != nil {
return fmt.Errorf("error syncing container history: %v", err)
}

g.Add(func() error {
Expand Down
18 changes: 9 additions & 9 deletions internal/yunikorn/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,13 @@ func (s *Service) syncApplications(ctx context.Context, applications []*dao.Appl
return nil
}

func (s *Service) syncHistory(
ctx context.Context,
appsHistory []*dao.ApplicationHistoryDAOInfo,
containersHistory []*dao.ContainerHistoryDAOInfo) error {

now := time.Now().UnixNano()
func (s *Service) syncAppHistory(ctx context.Context, appsHistory []*dao.ApplicationHistoryDAOInfo) error {
var errs []error
nowNano := time.Now().UnixNano()
for _, ah := range appsHistory {
history := &model.AppHistory{
Metadata: model.Metadata{
CreatedAtNano: now,
CreatedAtNano: nowNano,
},
ID: ulid.Make().String(),
ApplicationHistoryDAOInfo: *ah,
Expand All @@ -206,11 +202,16 @@ func (s *Service) syncHistory(
errs = append(errs, fmt.Errorf("could not insert app history: %v", err))
}
}
return errors.Join(errs...)
}

func (s *Service) syncContainerHistory(ctx context.Context, containersHistory []*dao.ContainerHistoryDAOInfo) error {
var errs []error
nowNano := time.Now().UnixNano()
for _, ch := range containersHistory {
history := &model.ContainerHistory{
Metadata: model.Metadata{
CreatedAtNano: now,
CreatedAtNano: nowNano,
},
ID: ulid.Make().String(),
ContainerHistoryDAOInfo: *ch,
Expand All @@ -219,6 +220,5 @@ func (s *Service) syncHistory(
errs = append(errs, fmt.Errorf("could not insert container history: %v", err))
}
}

return errors.Join(errs...)
}

0 comments on commit b91b2da

Please sign in to comment.