github.com/songzhibin97/gkit@v1.2.13/distributed/task/error.go (about) 1 package task 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 type errNonsupportType struct { 9 valueType string 10 } 11 12 func NewErrNonsupportType(valueType string) error { 13 return &errNonsupportType{valueType: valueType} 14 } 15 16 func (e *errNonsupportType) Error() string { 17 return e.valueType + ":不是支持类型" 18 } 19 20 // ErrRetryTaskLater 重试错误 21 type ErrRetryTaskLater struct { 22 msg string 23 retryIn time.Duration 24 } 25 26 // RetryIn 返回重试时间,从现在开始到执行的间隔 27 func (e ErrRetryTaskLater) RetryIn() time.Duration { 28 return e.retryIn 29 } 30 31 // Error 实现标准error接口 32 func (e ErrRetryTaskLater) Error() string { 33 return fmt.Sprintf("Task error: %s Will retry in: %s", e.msg, e.retryIn) 34 } 35 36 // NewErrRetryTaskLater 生成重试错误 37 func NewErrRetryTaskLater(msg string, retryIn time.Duration) ErrRetryTaskLater { 38 return ErrRetryTaskLater{msg: msg, retryIn: retryIn} 39 } 40 41 type Retrievable interface { 42 RetryIn() time.Duration 43 }