lease

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 6 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

Overview

Package lease implements the worker side of the work-lease protocol: it keeps exactly one outstanding lease request per queue and dispatches each assignment the server returns. The server gates capacity, so the worker simply runs what it is given. Replaces the JetStream pull loop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	QueueIDs       []string      // queues this worker serves (at least one)
	RequestTimeout time.Duration // long-poll request timeout; default 35s
	WorkerID       string        // included in each request
}

Config tunes the lease loop.

type Dispatcher

type Dispatcher interface {
	Dispatch(ctx context.Context, m *protocol.AssignMsg) error
}

Dispatcher executes one assignment.

type Loop

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

Loop runs one lease goroutine per queue.

func New

func New(t Transport, d Dispatcher, cfg Config, logger *slog.Logger) *Loop

New builds a Loop. A nil logger is replaced with a discard logger.

func (*Loop) Run

func (l *Loop) Run(ctx context.Context)

Run blocks until ctx is canceled, running one request loop per queue.

type Transport

type Transport interface {
	RequestLease(ctx context.Context, queueID string, data []byte, timeout time.Duration) ([]byte, error)
}

Transport sends a lease request and returns the server's reply bytes.

Jump to

Keyboard shortcuts

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