fix(server): Thread request context to all relevant places
Previously background contexts where created where necessary (e.g. in GCS interactions). Should I begin to use request timeouts or other context-dependent things in the future, it's useful to have the actual HTTP request context around. This threads the request context through the application to all places that need it.
This commit is contained in:
parent
30e618b65b
commit
d8fba23365
6 changed files with 20 additions and 23 deletions
|
|
@ -26,7 +26,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
|
@ -110,7 +109,6 @@ func writeError(w http.ResponseWriter, status int, code, message string) {
|
|||
}
|
||||
|
||||
type registryHandler struct {
|
||||
ctx context.Context
|
||||
state *builder.State
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +130,7 @@ func (h *registryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}).Info("requesting image manifest")
|
||||
|
||||
image := builder.ImageFromName(imageName, imageTag)
|
||||
buildResult, err := builder.BuildImage(h.ctx, h.state, &image)
|
||||
buildResult, err := builder.BuildImage(r.Context(), h.state, &image)
|
||||
|
||||
if err != nil {
|
||||
writeError(w, 500, "UNKNOWN", "image build failure")
|
||||
|
|
@ -211,7 +209,6 @@ func main() {
|
|||
|
||||
log.WithField("backend", s.Name()).Info("initialised storage backend")
|
||||
|
||||
ctx := context.Background()
|
||||
cache, err := builder.NewCache()
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("failed to instantiate build cache")
|
||||
|
|
@ -240,7 +237,6 @@ func main() {
|
|||
|
||||
// All /v2/ requests belong to the registry handler.
|
||||
http.Handle("/v2/", ®istryHandler{
|
||||
ctx: ctx,
|
||||
state: &state,
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue