Skip to content

Commit

Permalink
Fixup: Use same channel for clean-up and download
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomazic committed Jan 20, 2025
1 parent dc7a665 commit da9d9aa
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions go/runtime/bundle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ type Manager struct {
runtimeBaseURLs map[common.Namespace][]string
globalBaseURLs []string

downloadCh chan struct{}
downloadQueue map[common.Namespace][]hash.Hash
cleanupCh chan struct{}
cleanupQueue map[common.Namespace]version.Version
downloadAndCleanCh chan struct{}
downloadQueue map[common.Namespace][]hash.Hash
cleanupQueue map[common.Namespace]version.Version

client *http.Client
store ManifestStore
Expand Down Expand Up @@ -127,9 +126,8 @@ func NewManager(dataDir string, runtimeIDs []common.Namespace, store ManifestSto
runtimeIDs: runtimes,
globalBaseURLs: globalBaseURLs,
runtimeBaseURLs: runtimeBaseURLs,
downloadCh: make(chan struct{}, 1),
downloadAndCleanCh: make(chan struct{}, 1),
downloadQueue: make(map[common.Namespace][]hash.Hash),
cleanupCh: make(chan struct{}, 1),
cleanupQueue: make(map[common.Namespace]version.Version),
client: &client,
store: store,
Expand Down Expand Up @@ -202,15 +200,13 @@ func (m *Manager) run(ctx context.Context) {
for {
select {
case <-ticker.C:
case <-m.downloadCh:
case <-m.cleanupCh:
m.Clean()
continue
case <-m.downloadAndCleanCh:
case <-ctx.Done():
m.logger.Info("stopping")
return
}

m.Clean()
m.download()
}
}
Expand Down Expand Up @@ -249,9 +245,9 @@ func (m *Manager) Download(runtimeID common.Namespace, manifestHashes []hash.Has
}
m.downloadQueue[runtimeID] = hashes

// Trigger immediate download of new bundles.
// Trigger immediate download and clean-up of stale bundles.
select {
case m.downloadCh <- struct{}{}:
case m.downloadAndCleanCh <- struct{}{}:
default:
}
}
Expand All @@ -265,9 +261,9 @@ func (m *Manager) Cleanup(runtimeID common.Namespace, active version.Version) {

m.cleanupQueue[runtimeID] = active

// Trigger immediate clean-up of stale bundles.
// Trigger immediate download and clean-up of stale bundles.
select {
case m.cleanupCh <- struct{}{}:
case m.downloadAndCleanCh <- struct{}{}:
default:
}
}
Expand Down

0 comments on commit da9d9aa

Please sign in to comment.