Skip to content

Commit

Permalink
clients: Download segments from backup URL
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Jun 21, 2024
1 parent 0d1bd54 commit c90b2dc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions clients/input_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,30 @@ func GetFile(ctx context.Context, requestID, url string, dStorage *DStorageDownl
}
}

func GetFileWithBackup(ctx context.Context, requestID, url string, dStorage *DStorageDownload) (io.ReadCloser, error) {
rc, err := GetFile(ctx, requestID, url, dStorage)
if err == nil {
return rc, nil
}

backupURL := config.GetStorageBackupURL(url)
if backupURL == "" {
return nil, err
}
rc, backupErr := GetFile(ctx, requestID, backupURL, dStorage)
if backupErr == nil {
return rc, nil
}

// prioritize retriable errors in the response so we don't skip retries
if !xerrors.IsUnretriable(err) {
return nil, err
} else if !xerrors.IsUnretriable(backupErr) {
return nil, backupErr
}
return nil, err
}

var retryableHttpClient = newRetryableHttpClient()

func newRetryableHttpClient() *http.Client {
Expand Down
2 changes: 1 addition & 1 deletion clients/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func ClipInputManifest(requestID, sourceURL, clipTargetUrl string, startTimeUnix
segmentURL := sourceSegmentURLs[v.SeqId].URL
dStorage := NewDStorageDownload()
err = backoff.Retry(func() error {
rc, err := GetFile(context.Background(), requestID, segmentURL.String(), dStorage)
rc, err := GetFileWithBackup(context.Background(), requestID, segmentURL.String(), dStorage)
if err != nil {
return fmt.Errorf("error clipping: failed to download segment %d: %w", v.SeqId, err)
}
Expand Down
2 changes: 1 addition & 1 deletion thumbnails/thumbnails.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func GenerateThumbsFromManifest(requestID, input string, output *url.URL) error
)
// save the segment to memory
err = backoff.Retry(func() error {
rc, err = clients.GetFile(context.Background(), requestID, segURL.String(), nil)
rc, err = clients.GetFileWithBackup(context.Background(), requestID, segURL.String(), nil)
return err
}, clients.DownloadRetryBackoff())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion transcode/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func transcodeSegment(
err := backoff.Retry(func() error {
ctx, cancel := context.WithTimeout(context.Background(), clients.MaxCopyFileDuration)
defer cancel()
rc, err := clients.GetFile(ctx, transcodeRequest.RequestID, segment.Input.URL.String(), nil)
rc, err := clients.GetFileWithBackup(ctx, transcodeRequest.RequestID, segment.Input.URL.String(), nil)
if err != nil {
return fmt.Errorf("failed to download source segment %q: %w", segment.Input, err)
}
Expand Down

0 comments on commit c90b2dc

Please sign in to comment.