summaryrefslogtreecommitdiff
path: root/recording/task.go
diff options
context:
space:
mode:
Diffstat (limited to 'recording/task.go')
-rw-r--r--recording/task.go34
1 files changed, 31 insertions, 3 deletions
diff --git a/recording/task.go b/recording/task.go
index 3d417ba..78be348 100644
--- a/recording/task.go
+++ b/recording/task.go
@@ -8,7 +8,9 @@ Concrete task works are done in the `runner.go` file.
import (
"context"
"fmt"
+ "github.com/keuin/slbr/common"
"github.com/keuin/slbr/logging"
+ "time"
)
type TaskStatus int
@@ -31,8 +33,6 @@ type RunningTask struct {
TaskConfig
// ctx: the biggest context this task uses. It may create children contexts.
ctx context.Context
- // result: if the task is ended, here is the returned error
- result error
// status: running status
status TaskStatus
// hookStarted: called asynchronously when the task is started. This won't be called when restarting.
@@ -70,7 +70,7 @@ func (t *RunningTask) StartTask() error {
t.hookStarted()
defer t.hookStopped()
// do the task
- _ = t.runTaskWithAutoRestart()
+ t.runTaskWithAutoRestart()
}()
return nil
case StRunning:
@@ -85,3 +85,31 @@ func (t *RunningTask) StartTask() error {
}
panic(fmt.Errorf("invalid task status: %v", st))
}
+
+func AutoRetryWithTask[T any](
+ t *RunningTask,
+ supplier func() (T, error),
+) (T, error) {
+ return common.AutoRetry[T](
+ t.ctx,
+ supplier,
+ t.Transport.MaxRetryTimes,
+ time.Duration(t.Transport.RetryIntervalSeconds)*time.Second,
+ &t.logger,
+ )
+}
+
+func AutoRetryWithConfig[T any](
+ ctx context.Context,
+ logger logging.Logger,
+ t *TaskConfig,
+ supplier func() (T, error),
+) (T, error) {
+ return common.AutoRetry[T](
+ ctx,
+ supplier,
+ t.Transport.MaxRetryTimes,
+ time.Duration(t.Transport.RetryIntervalSeconds)*time.Second,
+ &logger,
+ )
+}