Skip to content

Commit

Permalink
rename config to globalConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Nov 24, 2023
1 parent 4c5d7a6 commit ef6a5bf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions zipserver/copy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func formatBytes(b float64) string {

// notify the callback URL of task completion
func notifyCallback(callbackURL string, resValues url.Values) error {
notifyCtx, notifyCancel := context.WithTimeout(context.Background(), time.Duration(config.AsyncNotificationTimeout))
notifyCtx, notifyCancel := context.WithTimeout(context.Background(), time.Duration(globalConfig.AsyncNotificationTimeout))
defer notifyCancel()

outBody := bytes.NewBufferString(resValues.Encode())
Expand Down Expand Up @@ -84,7 +84,7 @@ func copyHandler(w http.ResponseWriter, r *http.Request) error {
return err
}

storageTargetConfig := config.GetStorageTargetByName(targetName)
storageTargetConfig := globalConfig.GetStorageTargetByName(targetName)
if storageTargetConfig == nil {
return fmt.Errorf("Invalid target: %s", targetName)
}
Expand All @@ -108,10 +108,10 @@ func copyHandler(w http.ResponseWriter, r *http.Request) error {
go (func() {
defer copyLockTable.releaseKey(lockKey)

jobCtx, cancel := context.WithTimeout(context.Background(), time.Duration(config.JobTimeout))
jobCtx, cancel := context.WithTimeout(context.Background(), time.Duration(globalConfig.JobTimeout))
defer cancel()

storage, err := NewGcsStorage(config)
storage, err := NewGcsStorage(globalConfig)

if storage == nil {
notifyError(callbackURL, fmt.Errorf("Failed to create source storage: %v", err))
Expand All @@ -127,7 +127,7 @@ func copyHandler(w http.ResponseWriter, r *http.Request) error {

startTime := time.Now()

reader, headers, err := storage.GetFile(jobCtx, config.Bucket, key)
reader, headers, err := storage.GetFile(jobCtx, globalConfig.Bucket, key)

if err != nil {
log.Print("Failed to get file: ", err)
Expand Down
10 changes: 5 additions & 5 deletions zipserver/extract_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func extractHandler(w http.ResponseWriter, r *http.Request) error {
return writeJSONMessage(w, struct{ Processing bool }{true})
}

limits := loadLimits(params, config)
limits := loadLimits(params, globalConfig)

process := func(ctx context.Context) ([]ExtractedFile, error) {
archiver := NewArchiver(config)
archiver := NewArchiver(globalConfig)
files, err := archiver.ExtractZip(ctx, key, prefix, limits)

return files, err
Expand All @@ -80,7 +80,7 @@ func extractHandler(w http.ResponseWriter, r *http.Request) error {
if asyncURL == "" {
defer extractLockTable.releaseKey(key)

ctx, cancel := context.WithTimeout(r.Context(), time.Duration(config.JobTimeout))
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(globalConfig.JobTimeout))
defer cancel()

extracted, err := process(ctx)
Expand All @@ -99,7 +99,7 @@ func extractHandler(w http.ResponseWriter, r *http.Request) error {
defer extractLockTable.releaseKey(key)

// This job is expected to outlive the incoming request, so create a detached context.
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(config.JobTimeout))
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(globalConfig.JobTimeout))
defer cancel()

extracted, err := process(ctx)
Expand Down Expand Up @@ -127,7 +127,7 @@ func extractHandler(w http.ResponseWriter, r *http.Request) error {

log.Print("Notifying " + asyncURL)

nofityCtx, nofifyCancel := context.WithTimeout(context.Background(), time.Duration(config.AsyncNotificationTimeout))
nofityCtx, nofifyCancel := context.WithTimeout(context.Background(), time.Duration(globalConfig.AsyncNotificationTimeout))
defer nofifyCancel()

outBody := bytes.NewBufferString(resValues.Encode())
Expand Down
6 changes: 3 additions & 3 deletions zipserver/list_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func listZip(body []byte, w http.ResponseWriter, r *http.Request) error {
}

func listFromBucket(ctx context.Context, key string, w http.ResponseWriter, r *http.Request) error {
storage, err := NewGcsStorage(config)
storage, err := NewGcsStorage(globalConfig)
if storage == nil {
return err
}

reader, _, err := storage.GetFile(ctx, config.Bucket, key)
reader, _, err := storage.GetFile(ctx, globalConfig.Bucket, key)
if err != nil {
return err
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func listFromUrl(ctx context.Context, url string, w http.ResponseWriter, r *http
}

func listHandler(w http.ResponseWriter, r *http.Request) error {
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(config.FileGetTimeout))
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(globalConfig.FileGetTimeout))
defer cancel()

params := r.URL.Query()
Expand Down
2 changes: 1 addition & 1 deletion zipserver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ func (m *MetricsCounter) RenderMetrics(config *Config) string {
// render the global metrics
func metricsHandler(w http.ResponseWriter, r *http.Request) error {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(globalMetrics.RenderMetrics(config)))
w.Write([]byte(globalMetrics.RenderMetrics(globalConfig)))
return nil
}
4 changes: 2 additions & 2 deletions zipserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"
)

var config *Config
var globalConfig *Config

type wrapErrors func(http.ResponseWriter, *http.Request) error

Expand Down Expand Up @@ -95,7 +95,7 @@ func statusHandler(w http.ResponseWriter, r *http.Request) error {

// StartZipServer starts listening for extract and slurp requests
func StartZipServer(listenTo string, _config *Config) error {
config = _config
globalConfig = _config

// Extract a .zip file (downloaded from GCS), stores each
// individual file on GCS in a given bucket/prefix
Expand Down
12 changes: 6 additions & 6 deletions zipserver/slurp_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func slurpHandler(w http.ResponseWriter, r *http.Request) error {
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(config.JobTimeout))
ctx, cancel := context.WithTimeout(r.Context(), time.Duration(globalConfig.JobTimeout))
defer cancel()

params := r.URL.Query()
Expand Down Expand Up @@ -42,7 +42,7 @@ func slurpHandler(w http.ResponseWriter, r *http.Request) error {
}

process := func(ctx context.Context) error {
getCtx, cancel := context.WithTimeout(ctx, time.Duration(config.FileGetTimeout))
getCtx, cancel := context.WithTimeout(ctx, time.Duration(globalConfig.FileGetTimeout))
defer cancel()

log.Print("Fetching URL: ", slurpURL)
Expand Down Expand Up @@ -87,16 +87,16 @@ func slurpHandler(w http.ResponseWriter, r *http.Request) error {
log.Print("ACL: ", acl)
log.Print("Content-Disposition: ", contentDisposition)

storage, err := NewGcsStorage(config)
storage, err := NewGcsStorage(globalConfig)

if storage == nil {
log.Fatal("Failed to create storage:", err)
}

putCtx, cancel := context.WithTimeout(ctx, time.Duration(config.FilePutTimeout))
putCtx, cancel := context.WithTimeout(ctx, time.Duration(globalConfig.FilePutTimeout))
defer cancel()

return storage.PutFileWithSetup(putCtx, config.Bucket, key, body, func(req *http.Request) error {
return storage.PutFileWithSetup(putCtx, globalConfig.Bucket, key, body, func(req *http.Request) error {
req.Header.Add("Content-Type", contentType)

if contentDisposition != "" {
Expand Down Expand Up @@ -135,7 +135,7 @@ func slurpHandler(w http.ResponseWriter, r *http.Request) error {
resValues.Add("Success", "true")
}

ctx, cancel := context.WithTimeout(ctx, time.Duration(config.AsyncNotificationTimeout))
ctx, cancel := context.WithTimeout(ctx, time.Duration(globalConfig.AsyncNotificationTimeout))
defer cancel()

outBody := bytes.NewBufferString(resValues.Encode())
Expand Down

0 comments on commit ef6a5bf

Please sign in to comment.