| 313 | } |
| 314 | |
| 315 | func (s *Sync) monitorDiff(ctx context.Context, diff merger.Diff, rootsInfo map[string]*model.EndpointRootStat) chan bool { |
| 316 | indexStatus := make(chan model.Status) |
| 317 | done := make(chan interface{}) |
| 318 | finished := make(chan bool, 1) |
| 319 | diff.SetupChannels(indexStatus, done, s.cmd) |
| 320 | go func() { |
| 321 | defer close(finished) |
| 322 | for { |
| 323 | select { |
| 324 | case status := <-indexStatus: |
| 325 | if root, ok := rootsInfo[status.EndpointURI()]; ok { |
| 326 | if pgStatus, ok := s.computeIndexProgress(status, root); ok && pgStatus != nil { |
| 327 | log.Logger(ctx).Info(pgStatus.String()) |
| 328 | if s.statuses != nil { |
| 329 | s.statuses <- pgStatus |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | case <-done: |
| 334 | var totalStrings []string |
| 335 | var total int64 |
| 336 | for uri, root := range rootsInfo { |
| 337 | total += root.PgChildren |
| 338 | totalStrings = append(totalStrings, fmt.Sprintf("%d on %s", root.PgChildren, uri)) |
| 339 | } |
| 340 | tString := strings.Join(totalStrings, ", ") |
| 341 | log.Logger(ctx).Info(fmt.Sprintf("Finished analyze : %d nodes (%s)", total, tString), zap.Any("i", total)) |
| 342 | if s.statuses != nil { |
| 343 | for u := range rootsInfo { |
| 344 | s.statuses <- model.NewProcessingStatus("").SetEndpoint(u).SetProgress(0) |
| 345 | } |
| 346 | s.statuses <- model.NewProcessingStatus(fmt.Sprintf("Analyzed %d nodes (%s)", total, tString)) |
| 347 | } |
| 348 | // close(done) |
| 349 | // close(indexStatus) |
| 350 | return |
| 351 | } |
| 352 | } |
| 353 | }() |
| 354 | return finished |
| 355 | } |
| 356 | |
| 357 | func (s *Sync) computeIndexProgress(input model.Status, rootInfo *model.EndpointRootStat) (out model.Status, emit bool) { |
| 358 | if input.Node() == nil { |