store: pass the store to the jobqueue API

Drop the jobUpdates channel, and instead add an UpdateCompose method
to the store, which updates the status of a compose directly.

This allows us to report back errors directly, rather than having to
mirror the staet in the jobqueue API.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-10-05 17:35:31 +02:00 committed by Lars Karlitski
parent 89fd2e6037
commit 3ff4f59fc7
5 changed files with 34 additions and 39 deletions

View file

@ -7,6 +7,7 @@ import (
"net/http"
"osbuild-composer/internal/job"
"osbuild-composer/internal/pipeline"
"osbuild-composer/internal/store"
"osbuild-composer/internal/target"
"github.com/google/uuid"
@ -15,17 +16,17 @@ import (
type API struct {
pendingJobs <-chan job.Job
jobStatus chan<- job.Status
logger *log.Logger
store *store.Store
router *httprouter.Router
}
func New(logger *log.Logger, jobs <-chan job.Job, jobStatus chan<- job.Status) *API {
func New(logger *log.Logger, store *store.Store, jobs <-chan job.Job) *API {
api := &API{
logger: logger,
store: store,
pendingJobs: jobs,
jobStatus: jobStatus,
}
api.router = httprouter.New()
@ -127,6 +128,6 @@ func (api *API) updateJobHandler(writer http.ResponseWriter, request *http.Reque
statusResponseError(writer, http.StatusBadRequest, "invalid status: "+err.Error())
}
api.jobStatus <- job.Status{ComposeID: id, Status: body.Status}
api.store.UpdateCompose(id, body.Status)
statusResponseOK(writer)
}