Documentation ¶
Overview ¶
Package resilience provides helpers for dealing with resilience. This code is borrowed from https://github.com/ory/x/tree/master/resilience/retry.go
Index ¶
- Constants
- Variables
- func Retry(ctx context.Context, logger logrus.FieldLogger, maxWait time.Duration, ...) (err error)
- func WithFuncNewer(new func() (interface{}, error), ready func(x interface{}) error, ...) func() (Ptr, error)
- type Command
- type CommandSharedPtr
- func (g *CommandSharedPtr) AppendPostHandles(h ...func() error)
- func (g *CommandSharedPtr) AppendPreHandles(h ...func() error)
- func (g *CommandSharedPtr) Get() (*Command, error)
- func (g *CommandSharedPtr) GetUntilReady() (*Command, error)
- func (g *CommandSharedPtr) GetWithRetry() (*Command, error)
- func (g *CommandSharedPtr) Run() error
- type Event
- type Ptr
- type SharedPtr
- func BackgroundSharedPtr(ctx context.Context, l logrus.FieldLogger) *SharedPtr
- func NewSharedPtr(ctx context.Context, new func() (Ptr, error), l logrus.FieldLogger) *SharedPtr
- func NewSharedPtrFunc(ctx context.Context, new func() (interface{}, error), ...) *SharedPtr
- func TODOSharedPtr(ctx context.Context, l logrus.FieldLogger) *SharedPtr
- func (g *SharedPtr) AddTask(task *Task) error
- func (g *SharedPtr) AddTaskFunc(taskType TaskType, handle func() error, descriptions ...string) error
- func (g *SharedPtr) AddTaskFuncAsConstruct(handle func() error, descriptions ...string) error
- func (g *SharedPtr) AddTaskFuncAsConstructRepeat(handle func() error, descriptions ...string) error
- func (g *SharedPtr) AddTaskFuncAsRepeat(handle func() error, descriptions ...string) error
- func (g *SharedPtr) AddTaskFuncAsRetry(handle func() error, descriptions ...string) error
- func (g *SharedPtr) Context() context.Context
- func (g *SharedPtr) Get() Ptr
- func (g *SharedPtr) GetLogger() logrus.FieldLogger
- func (g *SharedPtr) GetTaskById(id string) (task *Task, has bool)
- func (g *SharedPtr) GetTasks() map[string]*Task
- func (g *SharedPtr) GetUntilReady() (Ptr, error)
- func (g *SharedPtr) GetWithRetry() (Ptr, error)
- func (g *SharedPtr) InShutdown() bool
- func (g *SharedPtr) Ready() error
- func (g *SharedPtr) Release() Ptr
- func (g *SharedPtr) RemoveAllTask()
- func (g *SharedPtr) RemoveTaskById(id string)
- func (g *SharedPtr) Reset()
- func (g *SharedPtr) TaskIds() []string
- func (g *SharedPtr) Watch() chan<- Event
- type Task
- type TaskState
- type TaskType
Constants ¶
const ( // DefaultConnectTimeout is the default timeout to establish a connection to // a ZooKeeper node. DefaultResilienceConstructTimeout = 0 // DefaultSessionTimeout is the default timeout to keep the current // ZooKeeper session alive during a temporary disconnect. DefaultResilienceTaskMaxRetryDuration = 15 * time.Second DefaultTaskRetryTimeout = 1 * time.Second DefaultTaskRescheduleTimeout = 1 * time.Second )
Variables ¶
Functions ¶
Types ¶
type Command ¶
func NewCommand ¶
func (*Command) AppendPostHandles ¶
func (*Command) AppendPreHandles ¶
type CommandSharedPtr ¶
type CommandSharedPtr struct { // contains filtered or unexported fields }
func NewCommandSharedPtr ¶
func NewCommandSharedPtr(ctx context.Context, cmd func() *exec.Cmd, preHandles []func() error, postHandles []func(err error) error, l logrus.FieldLogger) *CommandSharedPtr
func (*CommandSharedPtr) AppendPostHandles ¶
func (g *CommandSharedPtr) AppendPostHandles(h ...func() error)
func (*CommandSharedPtr) AppendPreHandles ¶
func (g *CommandSharedPtr) AppendPreHandles(h ...func() error)
func (*CommandSharedPtr) Get ¶
func (g *CommandSharedPtr) Get() (*Command, error)
func (*CommandSharedPtr) GetUntilReady ¶
func (g *CommandSharedPtr) GetUntilReady() (*Command, error)
func (*CommandSharedPtr) GetWithRetry ¶
func (g *CommandSharedPtr) GetWithRetry() (*Command, error)
func (*CommandSharedPtr) Run ¶
func (g *CommandSharedPtr) Run() error
type Event ¶
type Event int
func (Event) MarshalJSON ¶
MarshalJSON is generated so Event satisfies json.Marshaler.
func (*Event) UnmarshalJSON ¶
UnmarshalJSON is generated so Event satisfies json.Unmarshaler.
type Ptr ¶
type Ptr interface { Value() interface{} //actual instance Ready() error Close() }
type SharedPtr ¶
type SharedPtr struct { // contains filtered or unexported fields }
func BackgroundSharedPtr ¶
func BackgroundSharedPtr(ctx context.Context, l logrus.FieldLogger) *SharedPtr
BackgroundPtr returns a non-nil, empty Ptr.
func NewSharedPtr ¶
func NewSharedPtrFunc ¶
func TODOSharedPtr ¶
func TODOSharedPtr(ctx context.Context, l logrus.FieldLogger) *SharedPtr
TODO returns a non-nil, empty Ptr. Code should use context.TODO when it's unclear which Ptr to use or it is not yet available .
func (*SharedPtr) AddTaskFunc ¶
func (*SharedPtr) AddTaskFuncAsConstruct ¶
func (*SharedPtr) AddTaskFuncAsConstructRepeat ¶
func (*SharedPtr) AddTaskFuncAsRepeat ¶
func (*SharedPtr) AddTaskFuncAsRetry ¶
func (*SharedPtr) Context ¶
The returned context is always non-nil; it defaults to the background context.
func (*SharedPtr) GetLogger ¶
func (g *SharedPtr) GetLogger() logrus.FieldLogger
func (*SharedPtr) GetUntilReady ¶
std::shared_ptr.get() until ptr is ready & std::shared_ptr.make_unique() if necessary
func (*SharedPtr) GetWithRetry ¶
std::shared_ptr.get() & std::shared_ptr.make_unique() if necessary
func (*SharedPtr) InShutdown ¶
func (*SharedPtr) RemoveAllTask ¶
func (g *SharedPtr) RemoveAllTask()
func (*SharedPtr) RemoveTaskById ¶
type Task ¶
type Task struct { Type TaskType State TaskState Description string // for debug Handle func() error RepeatDuration time.Duration RetryDuration time.Duration Ctx context.Context CancelFn context.CancelFunc // contains filtered or unexported fields }
type TaskState ¶
type TaskState int
const ( TaskStateNew TaskState = iota // Task state for a task which has not yet started. TaskStateRunning // Task state for a running task. A task in the running state is executing in the Go routine but it may be waiting for other resources from the operating system such as processor. TaskStateDoneErrorHappened // Task state for a terminated state. The task has completed execution with some errors happened TaskStateDoneNormally // Task state for a terminated state. The task has completed execution normally TaskStateDormancy // Task state for a terminated state. The task has completed execution normally and will be started if New's called TaskStateDeath // Task state for a terminated state. The task has completed execution normally and will never be started again TaskStateButt )
func (TaskState) MarshalJSON ¶
MarshalJSON is generated so TaskState satisfies json.Marshaler.
func (*TaskState) UnmarshalJSON ¶
UnmarshalJSON is generated so TaskState satisfies json.Unmarshaler.