Skip to content

candango/intervalok

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IntervalOK

A Go library for series of time intervals: schedules that resolve in time.Duration, ready for time.Sleep, retry loops, and schedulers.

Each series type shares the same duration-first shape: given a reference time.Time, it tells you how long until the next occurrence (and, where it makes sense, how long since the previous one). The calendar or backoff math stays internal; the public contract is a duration.

Packages

  • cron — parses standard cron expressions and resolves the next/previous occurrence, in both absolute time and duration form.
  • backoff — pluggable exponential backoff strategies, with optional jitter, for retry policies.

backoff

bi := backoff.NewFullJitterBackoffInterval(500 * time.Millisecond)
for {
    if err := doSomething(); err != nil {
        time.Sleep(bi.Next())
        continue
    }
    break
}

BackoffInterval is a generic retry-delay engine: pluggable nextFunc/ resetFunc pairs drive the sequence, so new strategies plug in without new concrete types. Jitter strategies follow the AWS Architecture Blog reference "Exponential Backoff and Jitter":

Strategy Formula Constructor
FullJitter (default) random(0, interval) NewFullJitterBackoffInterval
EqualJitter interval/2 + random(0, interval/2) NewEqualJitterBackoffInterval
DecorrelatedJitter min(cap, random(base, prevSleep*3)) NewDecorrelatedBackoffInterval
PercentJitter interval ± Randomizer% (this package's own; not from the AWS reference) NewPercentJitterBackoffInterval

DecorrelatedJitter is structurally different from the other three: its recurrence depends on the previously returned sleep instead of a deterministic exponential ramp, so it runs as its own engine rather than a jitter strategy plugged into the exponential one.

WrapError attaches the current backoff interval to an error, without losing the original via errors.Is/errors.As:

if err != nil {
    return bi.WrapError(err)
}

Support

IntervalOK is one of the Candango Open Source Group initiatives.

For bug reports, feature requests, and questions, please open an issue on GitHub.

License

NvimIM is distributed under the MIT License. See the LICENSE file for details.

About

Flexible interval series for Go. Build schedules, retries, and workflows using cron-like or custom time intervals.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors