RetryInitRepository wraps provided initialization function with retries until the context gets canceled.
(initialize InitRepositoryFunc)
| 940 | |
| 941 | // RetryInitRepository wraps provided initialization function with retries until the context gets canceled. |
| 942 | func RetryInitRepository(initialize InitRepositoryFunc) InitRepositoryFunc { |
| 943 | return func(ctx context.Context) (repo.Repository, error) { |
| 944 | nextSleepTime := retryInitRepositorySleepOnError |
| 945 | |
| 946 | // async connection - keep trying to open repository until context gets canceled. |
| 947 | for { |
| 948 | if cerr := ctx.Err(); cerr != nil { |
| 949 | // context canceled, bail |
| 950 | //nolint:wrapcheck |
| 951 | return nil, cerr |
| 952 | } |
| 953 | |
| 954 | rep, rerr := initialize(ctx) |
| 955 | if rerr == nil { |
| 956 | return rep, nil |
| 957 | } |
| 958 | |
| 959 | userLog(ctx).Warnf("unable to open repository: %v, will keep trying until canceled. Sleeping for %v", rerr, nextSleepTime) |
| 960 | |
| 961 | if !clock.SleepInterruptibly(ctx, nextSleepTime) { |
| 962 | return nil, ctx.Err() |
| 963 | } |
| 964 | |
| 965 | nextSleepTime *= 2 |
| 966 | if nextSleepTime > maxRetryInitRepositorySleepOnError { |
| 967 | nextSleepTime = maxRetryInitRepositorySleepOnError |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | func (s *Server) runSnapshotTask(ctx context.Context, src snapshot.SourceInfo, inner func(ctx context.Context, ctrl uitask.Controller, result *notifydata.ManifestWithError) error) error { |
| 974 | if !s.beginUpload(ctx, src) { |
no test coverage detected