Skip to content

Commit

Permalink
Try restarting scoring worker if it randomly stops
Browse files Browse the repository at this point in the history
  • Loading branch information
J12934 committed Dec 27, 2024
1 parent 8b62f04 commit ffdb7b6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions balancer/pkg/scoring/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,19 @@ func (s *ScoringService) WaitForTeamUpdatesNewerThan(ctx context.Context, team s
}
}

// StartingScoringWorker starts a worker that listens for changes in JuiceShop deployments and updates the scores accordingly
func (s *ScoringService) StartingScoringWorker(ctx context.Context) {
for {
select {
case <-ctx.Done():
s.bundle.Log.Printf("MultiJuicer context canceled. Exiting the scoring watcher.")
return
default:
s.startScoringWatcher(ctx)
}
}
}

func (s *ScoringService) startScoringWatcher(ctx context.Context) {
watcher, err := s.bundle.ClientSet.AppsV1().Deployments(s.bundle.RuntimeEnvironment.Namespace).Watch(ctx, metav1.ListOptions{
LabelSelector: "app.kubernetes.io/name=juice-shop,app.kubernetes.io/part-of=multi-juicer",
})
Expand All @@ -175,7 +186,7 @@ func (s *ScoringService) StartingScoringWorker(ctx context.Context) {
select {
case event, ok := <-watcher.ResultChan():
if !ok {
s.bundle.Log.Printf("Watcher for JuiceShop deployments has been closed. Exiting the watcher.")
s.bundle.Log.Printf("Watcher for JuiceShop deployments has been closed. Restarting the watcher.")
return
}
switch event.Type {
Expand Down

0 comments on commit ffdb7b6

Please sign in to comment.