lease

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

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