feat: concurrently check and update all domains #24

Merged
t.behrendt merged 2 commits from feat-concurrency into main 2024-12-30 17:37:50 +01:00
Showing only changes of commit 16921d41f3 - Show all commits

View File

@@ -73,7 +73,7 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
var wg sync.WaitGroup
numberUpdated := make(chan int)
numberUpdatedChannel := make(chan int)
for _, domain := range c.domains {
for _, subdomain := range domain.Subdomains {
@@ -131,7 +131,7 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
return
}
numberUpdated <- 1
numberUpdatedChannel <- 1
}
}(domain, subdomain)
}
@@ -139,9 +139,14 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
go func() {
wg.Wait()
close(numberUpdated)
close(numberUpdatedChannel)
}()
c.logger.Info("Run completed", slog.Int("number_of_changes", <-numberUpdated))
return <-numberUpdated, nil
numberUpdated := 0
for v := range numberUpdatedChannel {
numberUpdated += v
}
c.logger.Info("Run completed", slog.Int("number_of_changes", numberUpdated))
return numberUpdated, nil
}