store: add {Push,Pop}Compose methods and hide channel

Wrap the channel in Pop and Push methods, so it is not exposed to
the callers. PushCompose replaces the old AddCompose for consistency,
and PopCompose simply reads from the other end of the channel.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-10-05 17:51:30 +02:00 committed by Lars Karlitski
parent 3ff4f59fc7
commit 9cb140795e
6 changed files with 23 additions and 37 deletions

View file

@ -25,7 +25,7 @@ type Store struct {
Composes map[uuid.UUID]Compose `json:"composes"`
mu sync.RWMutex // protects all fields
pendingJobs chan<- job.Job
pendingJobs chan job.Job
stateChannel chan<- []byte
}
@ -48,7 +48,7 @@ type Image struct {
Mime string
}
func New(initialState []byte, stateChannel chan<- []byte, pendingJobs chan<- job.Job) *Store {
func New(initialState []byte, stateChannel chan<- []byte) *Store {
var s Store
if initialState != nil {
@ -69,7 +69,7 @@ func New(initialState []byte, stateChannel chan<- []byte, pendingJobs chan<- job
s.Composes = make(map[uuid.UUID]Compose)
}
s.stateChannel = stateChannel
s.pendingJobs = pendingJobs
s.pendingJobs = make(chan job.Job, 200)
return &s
}
@ -254,7 +254,7 @@ func (s *Store) DeleteBlueprintFromWorkspace(name string) {
})
}
func (s *Store) AddCompose(composeID uuid.UUID, bp *blueprint.Blueprint, composeType string) {
func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, composeType string) {
targets := []*target.Target{
target.NewLocalTarget(target.NewLocalTargetOptions("/var/lib/osbuild-composer/outputs/" + composeID.String())),
}
@ -274,6 +274,10 @@ func (s *Store) AddCompose(composeID uuid.UUID, bp *blueprint.Blueprint, compose
}
}
func (s *Store) PopCompose() job.Job {
return <-s.pendingJobs
}
func (s *Store) UpdateCompose(composeID uuid.UUID, status string) {
s.change(func() {
compose, exists := s.Composes[composeID]