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
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 ¶
Dispatcher executes one assignment.
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
Loop runs one lease goroutine per queue.
type NATSTransport ¶ added in v0.4.0
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.