refactor(agent): Gather dashboard and deployment data concurrently by nfebe · Pull Request #162 · flatrun/agent · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 67 additions & 39 deletions internal/api/server.go
18 changes: 15 additions & 3 deletions internal/docker/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,22 @@ func (m *Manager) ListDeployments() ([]models.Deployment, error) {
return nil, err
}

// Each status check shells out to docker compose, so a serial loop makes
// list latency grow with the deployment count. Fetch them concurrently with
// a bounded worker pool; each goroutine writes only its own index.
var wg sync.WaitGroup
sem := make(chan struct{}, 12)
for i := range deployments {
status, _ := m.executor.GetStatus(deployments[i].Path)
deployments[i].Status = status
}
wg.Add(1)
go func(i int) {
defer wg.Done()
sem <- struct{}{}
defer func() { <-sem }()
status, _ := m.executor.GetStatus(deployments[i].Path)
deployments[i].Status = status
}(i)
}
wg.Wait()

return deployments, nil
}
Expand Down
38 changes: 28 additions & 10 deletions internal/networks/manager.go
Loading