mirror of
https://github.com/owncast/owncast.git
synced 2025-11-03 21:08:36 +08:00
Add basic file upload retry with a hardcoded limit
This commit is contained in:
@ -2,6 +2,6 @@ package main
|
|||||||
|
|
||||||
type ChunkStorage interface {
|
type ChunkStorage interface {
|
||||||
Setup(config Config)
|
Setup(config Config)
|
||||||
Save(filePath string) string
|
Save(filePath string, retryCount int) string
|
||||||
GenerateRemotePlaylist(playlist string, variant Variant) string
|
GenerateRemotePlaylist(playlist string, variant Variant) string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,7 @@ func (s *IPFSStorage) Setup(config Config) {
|
|||||||
s.createIPFSDirectory("./hls")
|
s.createIPFSDirectory("./hls")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IPFSStorage) Save(filePath string) string {
|
func (s *IPFSStorage) Save(filePath string, retryCount int) string {
|
||||||
someFile, err := getUnixfsNode(filePath)
|
someFile, err := getUnixfsNode(filePath)
|
||||||
defer someFile.Close()
|
defer someFile.Close()
|
||||||
|
|
||||||
|
|||||||
@ -108,7 +108,7 @@ func monitorVideoContent(pathToMonitor string, configuration Config, storage Chu
|
|||||||
|
|
||||||
newObjectPathChannel := make(chan string, 1)
|
newObjectPathChannel := make(chan string, 1)
|
||||||
go func() {
|
go func() {
|
||||||
newObjectPath := storage.Save(path.Join(configuration.PrivateHLSPath, segment.RelativeUploadPath))
|
newObjectPath := storage.Save(path.Join(configuration.PrivateHLSPath, segment.RelativeUploadPath), 0)
|
||||||
newObjectPathChannel <- newObjectPath
|
newObjectPathChannel <- newObjectPath
|
||||||
}()
|
}()
|
||||||
newObjectPath := <-newObjectPathChannel
|
newObjectPath := <-newObjectPathChannel
|
||||||
|
|||||||
10
s3Storage.go
10
s3Storage.go
@ -36,14 +36,14 @@ func (s *S3Storage) Setup(configuration Config) {
|
|||||||
s.sess = s.connectAWS()
|
s.sess = s.connectAWS()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *S3Storage) Save(filePath string) string {
|
func (s *S3Storage) Save(filePath string, retryCount int) string {
|
||||||
// fmt.Println("Saving", filePath)
|
// fmt.Println("Saving", filePath)
|
||||||
|
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Errorln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
uploader := s3manager.NewUploader(s.sess)
|
uploader := s3manager.NewUploader(s.sess)
|
||||||
@ -55,7 +55,11 @@ func (s *S3Storage) Save(filePath string) string {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
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)
|
// fmt.Println("Uploaded", filePath, "to", response.Location)
|
||||||
|
|||||||
Reference in New Issue
Block a user