lease

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.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

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QueueIDs added in v0.4.0

func QueueIDs(configured []string) []string

QueueIDs maps a worker's configured queue list to the queues it requests leases on. A worker with no configured queues serves any queue; it must still request on a valid subject, so it uses bus.WildcardQueueToken (work.lease.<worker>._any) rather than an empty queue token, which routes to no responder. The server selects tasks farm-wide and gates by eligibility, so a queue-unaffiliated worker is matched to any queue's ready work.

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
	// InstanceID is this worker process's instance ID (the one its
	// registration carries), included in each request so the server can hold
	// work back from a restarted process until its registration has landed.
	// Empty sends none.
	InstanceID string
}

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 NATSTransport added in v0.4.0

type NATSTransport struct {
	NC *nats.Conn
}

NATSTransport adapts a raw *nats.Conn to Transport, issuing core-NATS request/reply work-lease requests on the work.lease.<worker>.<queue> subject. It provides the same RequestLease behavior as bus.Client.RequestLease without a second client connection.

func (NATSTransport) RequestLease added in v0.4.0

func (t NATSTransport) RequestLease(ctx context.Context, workerID, queueID string, data []byte, timeout time.Duration) ([]byte, error)

RequestLease sends a work-lease request for queueID on behalf of workerID and waits up to timeout for the server's reply. It returns the raw reply bytes (a marshaled leaseReply) for the lease loop to decode.

type Transport

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

Transport sends a lease request and returns the server's reply bytes. workerID identifies the requesting worker; it is a token of the subject the request travels on, which is how the server attributes the request.

Jump to

Keyboard shortcuts

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