shad-go/distbuild/pkg/worker/download.go

46 lines
1 KiB
Go
Raw Normal View History

2020-04-04 21:49:25 +00:00
package worker
import (
"context"
"errors"
2020-04-05 11:29:46 +00:00
"gitlab.com/slon/shad-go/distbuild/pkg/api"
"gitlab.com/slon/shad-go/distbuild/pkg/artifact"
2020-04-04 21:49:25 +00:00
"gitlab.com/slon/shad-go/distbuild/pkg/build"
"gitlab.com/slon/shad-go/distbuild/pkg/filecache"
)
2020-04-05 11:29:46 +00:00
func (w *Worker) downloadFiles(ctx context.Context, files map[build.ID]string) error {
2020-04-04 21:49:25 +00:00
for id := range files {
_, unlock, err := w.fileCache.Get(id)
if errors.Is(err, filecache.ErrNotFound) {
2020-04-04 21:55:07 +00:00
if err = w.fileClient.Download(ctx, w.fileCache, id); err != nil {
2020-04-04 21:49:25 +00:00
return err
}
} else if err != nil {
return err
} else {
unlock()
}
}
return nil
}
2020-04-05 11:29:46 +00:00
func (w *Worker) downloadArtifacts(ctx context.Context, artifacts map[build.ID]api.WorkerID) error {
for id, worker := range artifacts {
_, unlock, err := w.artifacts.Get(id)
if errors.Is(err, artifact.ErrNotFound) {
if err = artifact.Download(ctx, worker.String(), w.artifacts, id); err != nil {
return err
}
} else if err != nil {
return err
} else {
unlock()
}
}
return nil
}