fix: add error handler if we max out our retries

This commit is contained in:
Derrick Hammer 2024-02-01 19:26:23 -05:00
parent c1915321e1
commit dc9b3b4fda
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 17 additions and 3 deletions

View File

@ -3,7 +3,9 @@ package renter
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"git.lumeweb.com/LumeWeb/portal/cron" "git.lumeweb.com/LumeWeb/portal/cron"
"github.com/google/uuid"
"github.com/spf13/viper" "github.com/spf13/viper"
rhpv2 "go.sia.tech/core/rhp/v2" rhpv2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/renterd/api" "go.sia.tech/renterd/api"
@ -167,7 +169,8 @@ func (r *RenterDefault) MultipartUpload(params MultiPartUploadParams) error {
if end > size { if end > size {
end = size end = size
} }
next := make(chan struct{}, 0) nextChan := make(chan struct{}, 0)
errChan := make(chan error, 0)
job := r.cron.RetryableTask(cron.RetryableTaskParams{ job := r.cron.RetryableTask(cron.RetryableTaskParams{
Name: fileName + "-part-" + strconv.FormatUint(i, 10), Name: fileName + "-part-" + strconv.FormatUint(i, 10),
@ -189,10 +192,16 @@ func (r *RenterDefault) MultipartUpload(params MultiPartUploadParams) error {
return err return err
} }
next <- struct{}{} nextChan <- struct{}{}
return nil return nil
}, },
Limit: 10, Limit: 10,
Error: func(jobID uuid.UUID, jobName string, err error) {
if errors.Is(err, cron.ErrRetryLimitReached) {
r.logger.Error("failed to upload part", zap.String("jobName", jobName), zap.Error(err))
errChan <- err
}
},
}) })
_, err = r.cron.CreateJob(job) _, err = r.cron.CreateJob(job)
@ -205,7 +214,12 @@ func (r *RenterDefault) MultipartUpload(params MultiPartUploadParams) error {
PartNumber: int(i), PartNumber: int(i),
} }
<-next select {
case err = <-errChan:
return fmt.Errorf("failed to upload part %d: %s", i, err.Error())
case <-nextChan:
}
} }
_, err = r.busClient.CompleteMultipartUpload(ctx, bucket, fileName, upload.UploadID, uploadParts) _, err = r.busClient.CompleteMultipartUpload(ctx, bucket, fileName, upload.UploadID, uploadParts)