Skip to content

Commit

Permalink
chore: retry upload of statics
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMenoti committed May 16, 2024
1 parent 1bdf5a4 commit 4b2c870
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 9 additions & 5 deletions pkg/cmd/deploy/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
"go.uber.org/zap"
)

var PathStatic = ".edge/storage"
var (
PathStatic = ".edge/storage"
Jobs chan contracts.FileOps
Retries int64
)

func (cmd *DeployCmd) uploadFiles(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions) error {
// Get total amount of files to display progress
Expand All @@ -40,12 +44,12 @@ func (cmd *DeployCmd) uploadFiles(f *cmdutil.Factory, conf *contracts.AzionAppli

noOfWorkers := 5
var currentFile int64
jobs := make(chan contracts.FileOps, totalFiles)
Jobs := make(chan contracts.FileOps, totalFiles)
results := make(chan error, noOfWorkers)

// Create worker goroutines
for i := 1; i <= noOfWorkers; i++ {
go worker(jobs, results, &currentFile, clientUpload, conf)
go worker(Jobs, results, &currentFile, clientUpload, conf)
}

bar := progressbar.NewOptions(
Expand Down Expand Up @@ -84,14 +88,14 @@ func (cmd *DeployCmd) uploadFiles(f *cmdutil.Factory, conf *contracts.AzionAppli
FileContent: fileContent,
}

jobs <- fileOptions
Jobs <- fileOptions
}
return nil
}); err != nil {
logger.Debug("Error while reading files to be uploaded", zap.Error(err))
return err
}
close(jobs)
close(Jobs)

// Check for errors from workers
for a := 1; a <= totalFiles; a++ {
Expand Down
12 changes: 11 additions & 1 deletion pkg/cmd/deploy/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

// worker reads the range of jobs and uploads the file, if there is an error during upload, we returning it through the results channel
func worker(jobs <-chan contracts.FileOps, results chan<- error, currentFile *int64, clientUpload *storage.Client, conf *contracts.AzionApplicationOptions) {

for job := range jobs {
// Once ENG-27343 is completed, we might be able to remove this piece of code
fileInfo, err := job.FileContent.Stat()
Expand All @@ -30,11 +29,22 @@ func worker(jobs <-chan contracts.FileOps, results chan<- error, currentFile *in
return
}

// for

if err := clientUpload.Upload(context.Background(), &job, conf); err != nil {
logger.Debug("Error while worker tried to upload file: <"+job.Path+"> to storage api", zap.Error(err))
if Retries < 5 {
logger.Debug("Retrying to upload the following file: <"+job.Path+"> to storage api", zap.Error(err))
atomic.AddInt64(&Retries, 1)
Jobs <- job
results <- nil
return
}
logger.Debug("There have been 5 retries already, quitting upload")
results <- err
return
}

atomic.AddInt64(currentFile, 1)
results <- nil
}
Expand Down

0 comments on commit 4b2c870

Please sign in to comment.