From e63d0656ba43f80f10766df6e1ff1c8a2cc1db93 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 17 Jun 2020 22:01:53 -0700 Subject: [PATCH] Add basic file upload retry with a hardcoded limit --- chunkStorage.go | 2 +- ipfsStorage.go | 2 +- playlistMonitor.go | 2 +- s3Storage.go | 10 +++++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/chunkStorage.go b/chunkStorage.go index ddb86ce9c..16ba6dbdb 100644 --- a/chunkStorage.go +++ b/chunkStorage.go @@ -2,6 +2,6 @@ package main type ChunkStorage interface { Setup(config Config) - Save(filePath string) string + Save(filePath string, retryCount int) string GenerateRemotePlaylist(playlist string, variant Variant) string } diff --git a/ipfsStorage.go b/ipfsStorage.go index 6208dc26e..a59bbe810 100644 --- a/ipfsStorage.go +++ b/ipfsStorage.go @@ -52,7 +52,7 @@ func (s *IPFSStorage) Setup(config Config) { s.createIPFSDirectory("./hls") } -func (s *IPFSStorage) Save(filePath string) string { +func (s *IPFSStorage) Save(filePath string, retryCount int) string { someFile, err := getUnixfsNode(filePath) defer someFile.Close() diff --git a/playlistMonitor.go b/playlistMonitor.go index 5cd68d767..71c865dc4 100644 --- a/playlistMonitor.go +++ b/playlistMonitor.go @@ -108,7 +108,7 @@ func monitorVideoContent(pathToMonitor string, configuration Config, storage Chu newObjectPathChannel := make(chan string, 1) go func() { - newObjectPath := storage.Save(path.Join(configuration.PrivateHLSPath, segment.RelativeUploadPath)) + newObjectPath := storage.Save(path.Join(configuration.PrivateHLSPath, segment.RelativeUploadPath), 0) newObjectPathChannel <- newObjectPath }() newObjectPath := <-newObjectPathChannel diff --git a/s3Storage.go b/s3Storage.go index e9b0e0d5d..72cef7224 100644 --- a/s3Storage.go +++ b/s3Storage.go @@ -36,14 +36,14 @@ func (s *S3Storage) Setup(configuration Config) { s.sess = s.connectAWS() } -func (s *S3Storage) Save(filePath string) string { +func (s *S3Storage) Save(filePath string, retryCount int) string { // fmt.Println("Saving", filePath) file, err := os.Open(filePath) defer file.Close() if err != nil { - log.Fatal(err) + log.Errorln(err) } uploader := s3manager.NewUploader(s.sess) @@ -55,7 +55,11 @@ func (s *S3Storage) Save(filePath string) string { }) if err != nil { - panic(err) + log.Errorln(err) + if retryCount < 4 { + log.Println("Retrying...") + s.Save(filePath, retryCount+1) + } } // fmt.Println("Uploaded", filePath, "to", response.Location)