Documentation
¶
Index ¶
- Constants
- Variables
- func AutoRenew(enabled bool) autoRenewOption
- func Meta(key string, value any) metaOption
- func Prefix(value string) prefixOption
- func Provider(options ...ProviderOption) runaprovider.Provider
- func RetryInterval(duration time.Duration) retryIntervalOption
- func TTL(duration time.Duration) ttlOption
- func Wait(duration time.Duration) waitOption
- type Driver
- type DriverOption
- type DriverOptions
- type Info
- type Lease
- type LockOption
- type Locker
- type LockerOption
- type Options
- type ProviderOption
- type Registry
- func (registry *Registry) Close(ctx context.Context) error
- func (registry *Registry) Config(store *config.Store)
- func (registry *Registry) Driver(name string) Driver
- func (registry *Registry) Info() []Info
- func (registry *Registry) Locker(name string, options ...LockerOption)
- func (registry *Registry) MustOf(name string) Locker
- func (registry *Registry) Of(name string) (Locker, error)
- func (registry *Registry) RegisterDriver(name string, driver Driver)
- func (registry *Registry) Shutdown(ctx context.Context) error
- type State
Constants ¶
const ( DefaultName = "default" Local = "local" Schedule = "schedule" Queue = "queue" Cache = "cache" DefaultDriver = "memory" DefaultTTL = 30 * time.Second DefaultWait = 3 * time.Second DefaultRetryInterval = 100 * time.Millisecond DefaultRedisPrefix = "runa:lock:" )
Variables ¶
var ( ErrTimeout = errors.New("lock wait timeout") ErrNotHeld = errors.New("lock is not held") )
Functions ¶
func AutoRenew ¶
func AutoRenew(enabled bool) autoRenewOption
AutoRenew enables or disables automatic lease renew in With.
func Prefix ¶
func Prefix(value string) prefixOption
Prefix sets a key prefix for a locker or store.
func Provider ¶
func Provider(options ...ProviderOption) runaprovider.Provider
func RetryInterval ¶
RetryInterval sets polling interval while waiting.
Types ¶
type Driver ¶
type Driver interface {
Name() string
Try(ctx context.Context, key string, token string, ttl time.Duration) (State, bool, error)
Renew(ctx context.Context, key string, token string, ttl time.Duration) error
Release(ctx context.Context, key string, token string) error
Close(ctx context.Context) error
}
Driver is the primitive lock storage contract.
func MemoryDriver ¶
func MemoryDriver(options ...DriverOption) Driver
MemoryDriver creates a single-process lock driver.
type DriverOption ¶
type DriverOption interface {
ApplyDriver(*DriverOptions)
}
DriverOption configures a lock driver.
func DriverMeta ¶
func DriverMeta(key string, value any) DriverOption
DriverMeta sets lock driver metadata.
type DriverOptions ¶
DriverOptions stores backend lock driver settings.
type Info ¶
type Info struct {
Name string
Driver string
Prefix string
TTL time.Duration
Wait time.Duration
RetryInterval time.Duration
AutoRenew bool
Meta core.Map
}
Info describes a configured lock pool.
type Lease ¶
type Lease interface {
Key() string
Token() string
Fencing() uint64
Renew(ctx context.Context, ttl time.Duration) error
Release(ctx context.Context) error
}
Lease is an acquired lock handle.
type LockOption ¶
type LockOption interface {
ApplyLock(*Options)
}
LockOption configures one lock acquisition.
type Locker ¶
type Locker interface {
Try(ctx context.Context, key string, options ...LockOption) (Lease, bool, error)
Wait(ctx context.Context, key string, options ...LockOption) (Lease, error)
With(ctx context.Context, key string, fn func(context.Context) error, options ...LockOption) error
}
Locker is a named lock pool.
type LockerOption ¶
type LockerOption interface {
ApplyLocker(*Options)
}
LockerOption configures a named locker.
func Use ¶
func Use(name string) LockerOption
Driver selects the backing lock driver used by a locker.
type Options ¶
type Options struct {
Driver string
Prefix string
TTL time.Duration
Wait time.Duration
RetryInterval time.Duration
AutoRenew bool
Meta core.Map
}
Options stores locker and lock-call settings.
type ProviderOption ¶
type ProviderOption func(*provider)
func RegisterDriver ¶
func RegisterDriver(name string, driver Driver) ProviderOption
func RegisterLocker ¶
func RegisterLocker(name string, options ...LockerOption) ProviderOption
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores lock drivers and named lockers.
func (*Registry) Locker ¶
func (registry *Registry) Locker(name string, options ...LockerOption)
Locker registers a named locker.
func (*Registry) RegisterDriver ¶
RegisterDriver registers a lock driver.