worker: add file resolve job
Implement a file resolution job which fetches the contents of a remote file.
This commit is contained in:
parent
b7e7bafb2e
commit
4fee181fec
2 changed files with 82 additions and 0 deletions
81
cmd/osbuild-worker/jobimpl-file-resolve.go
Normal file
81
cmd/osbuild-worker/jobimpl-file-resolve.go
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/remotefile"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
|
||||
)
|
||||
|
||||
type FileResolveJobImpl struct{}
|
||||
|
||||
func (impl *FileResolveJobImpl) Run(job worker.Job) error {
|
||||
logWithId := logrus.WithField("jobId", job.Id())
|
||||
|
||||
var err error
|
||||
result := worker.FileResolveJobResult{
|
||||
Success: false,
|
||||
Results: []worker.FileResolveJobResultItem{},
|
||||
}
|
||||
|
||||
defer func() {
|
||||
logWithId := logrus.WithField("jobId", job.Id().String())
|
||||
if result.JobError != nil {
|
||||
logWithId.Errorf("file content resolve job failed: %s", result.JobError.Reason)
|
||||
if result.JobError.Details != nil {
|
||||
logWithId.Errorf("failure details: %v", result.JobError.Details)
|
||||
}
|
||||
}
|
||||
|
||||
if result.Results == nil || len(result.Results) == 0 {
|
||||
logWithId.Infof("Resolving file contents failed: %v", err)
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
clienterrors.ErrorRemoteFileResolution,
|
||||
"Error resolving file contents",
|
||||
"All remote file contents returned empty",
|
||||
)
|
||||
}
|
||||
|
||||
err := job.Update(result)
|
||||
if err != nil {
|
||||
logWithId.Errorf("Error reporting job result: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
var args worker.FileResolveJob
|
||||
err = job.Args(&args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logWithId.Infof("Resolving file contents (%d)", len(args.URLs))
|
||||
|
||||
resolver := remotefile.NewResolver()
|
||||
for _, url := range args.URLs {
|
||||
resolver.Add(url)
|
||||
}
|
||||
|
||||
resultItems := resolver.Finish()
|
||||
|
||||
for idx := range resultItems {
|
||||
result.Results = append(result.Results, worker.FileResolveJobResultItem{
|
||||
URL: resultItems[idx].URL,
|
||||
Content: resultItems[idx].Content,
|
||||
ResolutionError: resultItems[idx].ResolutionError,
|
||||
})
|
||||
}
|
||||
|
||||
resolutionErrors := result.ResolutionErrors()
|
||||
if len(resolutionErrors) == 0 {
|
||||
result.Success = true
|
||||
} else {
|
||||
result.JobError = clienterrors.WorkerClientError(
|
||||
clienterrors.ErrorRemoteFileResolution,
|
||||
"at least one file resolution failed",
|
||||
resolutionErrors,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -466,6 +466,7 @@ func main() {
|
|||
AuthFilePath: containersAuthFilePath,
|
||||
},
|
||||
worker.JobTypeOSTreeResolve: &OSTreeResolveJobImpl{},
|
||||
worker.JobTypeFileResolve: &FileResolveJobImpl{},
|
||||
worker.JobTypeAWSEC2Copy: &AWSEC2CopyJobImpl{
|
||||
AWSCreds: awsCredentials,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue