Skip to content

Commit

Permalink
extract into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mjh1 committed Feb 28, 2023
1 parent 661cccf commit 2015667
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion clients/arweave_ipfs_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func CopyDStorageToS3(url, s3URL string, requestID string) error {
}

return nil
}, backoff.WithMaxRetries(backoff.NewConstantBackOff(1*time.Second), 2))
}, DStorageRetryBackoff())
}

func DownloadDStorageFromGatewayList(u string, requestID string) (io.ReadCloser, error) {
Expand Down Expand Up @@ -126,3 +126,7 @@ func parseDStorageGatewayURL(u *url.URL) (string, string, string) {

return "", "", ""
}

func DStorageRetryBackoff() backoff.BackOff {
return backoff.WithMaxRetries(backoff.NewConstantBackOff(1*time.Second), 2)
}
6 changes: 1 addition & 5 deletions clients/input_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func CopyFile(ctx context.Context, sourceURL, destOSBaseURL, filename, requestID
content := io.TeeReader(c, &byteAccWriter)

return UploadToOSURL(destOSBaseURL, filename, content, MAX_COPY_FILE_DURATION)
}, RetryBackoff())
}, UploadRetryBackoff())
return
}

Expand Down Expand Up @@ -153,7 +153,3 @@ type StubInputCopy struct{}
func (s *StubInputCopy) CopyInputToS3(requestID string, inputFile, osTransferURL *url.URL) (inputVideoProbe video.InputVideo, signedURL string, err error) {
return video.InputVideo{}, "", nil
}

func RetryBackoff() backoff.BackOff {
return backoff.WithMaxRetries(newExponentialBackOffExecutor(), 5)
}
4 changes: 4 additions & 0 deletions clients/object_store_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ func newExponentialBackOffExecutor() *backoff.ExponentialBackOff {

return backOff
}

func UploadRetryBackoff() backoff.BackOff {
return backoff.WithMaxRetries(newExponentialBackOffExecutor(), 5)
}
7 changes: 3 additions & 4 deletions transcode/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path"
"sort"
"strings"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/grafov/m3u8"
Expand All @@ -29,7 +28,7 @@ func DownloadRenditionManifest(sourceManifestOSURL string) (m3u8.MediaPlaylist,
return fmt.Errorf("error decoding manifest: %s", err)
}
return nil
}, backoff.WithMaxRetries(backoff.NewConstantBackOff(5*time.Second), 10))
}, TranscodeRetryBackoff())
if err != nil {
return m3u8.MediaPlaylist{}, err
}
Expand Down Expand Up @@ -139,7 +138,7 @@ func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL s
renditionManifestBaseURL := fmt.Sprintf("%s/%s", targetOSURL, profile.Name)
err = backoff.Retry(func() error {
return clients.UploadToOSURL(renditionManifestBaseURL, manifestFilename, strings.NewReader(renditionPlaylist.String()), UPLOAD_TIMEOUT)
}, clients.RetryBackoff())
}, clients.UploadRetryBackoff())
if err != nil {
return "", fmt.Errorf("failed to upload rendition playlist: %s", err)
}
Expand All @@ -153,7 +152,7 @@ func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL s

err := backoff.Retry(func() error {
return clients.UploadToOSURL(targetOSURL, MASTER_MANIFEST_FILENAME, strings.NewReader(masterPlaylist.String()), UPLOAD_TIMEOUT)
}, clients.RetryBackoff())
}, clients.UploadRetryBackoff())
if err != nil {
return "", fmt.Errorf("failed to upload master playlist: %s", err)
}
Expand Down
8 changes: 6 additions & 2 deletions transcode/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func transcodeSegment(
}
}
return nil
}, backoff.WithMaxRetries(backoff.NewConstantBackOff(5*time.Second), 10))
}, TranscodeRetryBackoff())

if err != nil {
return err
Expand All @@ -208,7 +208,7 @@ func transcodeSegment(

err = backoff.Retry(func() error {
return clients.UploadToOSURL(targetRenditionURL, fmt.Sprintf("%d.ts", segment.Index), bytes.NewReader(transcodedSegment.MediaData), UPLOAD_TIMEOUT)
}, clients.RetryBackoff())
}, clients.UploadRetryBackoff())
if err != nil {
return fmt.Errorf("failed to upload master playlist: %s", err)
}
Expand Down Expand Up @@ -274,3 +274,7 @@ type RenditionStats struct {
ManifestLocation string
BitsPerSecond uint32
}

func TranscodeRetryBackoff() backoff.BackOff {
return backoff.WithMaxRetries(backoff.NewConstantBackOff(5*time.Second), 10)
}

0 comments on commit 2015667

Please sign in to comment.