libroutine

package
v1.0.0-rc.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRunning = errors.New("libroutine: job is already running")
View Source
var ErrCircuitOpen = errors.New("circuit breaker is open")

Functions

func GetGroup added in v0.28.0

func GetGroup() *group

Types

type Condition

type Condition func(ctx context.Context) (bool, error)

type Job

type Job struct {
	Name      string
	Condition Condition
	Operation Operation
	Next      *Job
}

type LoopConfig

type LoopConfig struct {
	Key          string
	Threshold    int
	ResetTimeout time.Duration
	Interval     time.Duration
	Operation    func(ctx context.Context) error
}

type Operation

type Operation func(ctx context.Context) error

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(threshold int, resetTimeout time.Duration) *Pool

func (*Pool) Allow

func (p *Pool) Allow(key string) bool

func (*Pool) AllowAt

func (p *Pool) AllowAt(key string, now time.Time) bool

func (*Pool) Get

func (p *Pool) Get(key string) *Routine

func (*Pool) MarkSuccess

func (p *Pool) MarkSuccess(key string)

func (*Pool) WouldAllowAt

func (p *Pool) WouldAllowAt(key string, now time.Time) bool

type Routine

type Routine struct {
	// contains filtered or unexported fields
}

func NewRoutine

func NewRoutine(threshold int, resetTimeout time.Duration) *Routine

func (*Routine) Allow

func (rm *Routine) Allow() bool

func (*Routine) AllowAt

func (rm *Routine) AllowAt(now time.Time) bool

func (*Routine) Execute

func (rm *Routine) Execute(ctx context.Context, fn func(ctx context.Context) error) error

func (*Routine) ExecuteWithRetry

func (rm *Routine) ExecuteWithRetry(ctx context.Context, interval time.Duration, iterations int, fn func(ctx context.Context) error) error

func (*Routine) ForceClose

func (rm *Routine) ForceClose()

func (*Routine) ForceOpen

func (rm *Routine) ForceOpen()

func (*Routine) ForceOpenAt

func (rm *Routine) ForceOpenAt(now time.Time)

func (*Routine) GetResetTimeout

func (rm *Routine) GetResetTimeout() time.Duration

func (*Routine) GetState

func (rm *Routine) GetState() State

func (*Routine) GetThreshold

func (rm *Routine) GetThreshold() int

func (*Routine) Loop

func (rm *Routine) Loop(ctx context.Context, interval time.Duration, triggerChan <-chan struct{}, fn func(ctx context.Context) error, errHandling func(err error))

func (*Routine) MarkFailure

func (rm *Routine) MarkFailure()

func (*Routine) MarkFailureAt

func (rm *Routine) MarkFailureAt(now time.Time)

func (*Routine) MarkSuccess

func (rm *Routine) MarkSuccess()

func (*Routine) WouldAllowAt

func (rm *Routine) WouldAllowAt(now time.Time) bool

type RunResult

type RunResult struct {
	Name     string
	Skipped  bool
	Err      error
	Duration time.Duration
	Next     *RunResult
}

func (*RunResult) Failed

func (r *RunResult) Failed() bool

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(job *Job, threshold int, resetTimeout time.Duration, opts ...RunnerOption) *Runner

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) (*RunResult, error)

func (*Runner) Running

func (r *Runner) Running() bool

func (*Runner) StartSchedule

func (r *Runner) StartSchedule(ctx context.Context, sched Schedule)

func (*Runner) SubscribeMessenger

func (r *Runner) SubscribeMessenger(ctx context.Context, bus libbus.Messenger, subject string) (libbus.Subscription, error)

func (*Runner) Trigger

func (r *Runner) Trigger(ctx context.Context)

type RunnerOption

type RunnerOption func(*Runner)

func WithResultHook

func WithResultHook(fn func(*RunResult)) RunnerOption

func WithTracker

func WithTracker(tracker libtracker.ActivityTracker) RunnerOption

type Schedule

type Schedule interface {
	Next(t time.Time) time.Time
}

func Every

func Every(d time.Duration) Schedule

type State

type State int
const (
	Closed State = iota
	Open
	HalfOpen
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL