worker

package
v0.0.0-...-a9154ef Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitHeartbeat

func EmitHeartbeat(nc *nats.Conn, payload []byte) error

EmitHeartbeat publishes a heartbeat once. Call repeatedly on a ticker.

func HeartbeatLoop

func HeartbeatLoop(ctx context.Context, nc *nats.Conn, payloadFn func() ([]byte, error))

HeartbeatLoop emits heartbeats until ctx is done.

func HeartbeatPayload

func HeartbeatPayload(workerID, pool string, activeJobs, maxParallel int, cpuLoad float32) ([]byte, error)

HeartbeatPayload returns a protobuf-encoded heartbeat envelope.

Types

type Handler

Handler processes a JobRequest and returns a JobResult.

type NATSConn

type NATSConn interface {
	Publish(subject string, data []byte) error
	QueueSubscribe(subj, queue string, cb nats.MsgHandler) (*nats.Subscription, error)
}

NATSConn is an interface that represents a NATS connection.

type Worker

type Worker struct {
	NATS       NATSConn
	Subject    string
	Handler    Handler
	PublicKeys map[string]*ecdsa.PublicKey
	PrivateKey *ecdsa.PrivateKey
	SenderID   string
}

Worker subscribes to a pool subject and handles jobs.

func (*Worker) Start

func (w *Worker) Start() error

Start begins consuming and handling JobRequests. It blocks until the subscription is closed.

Jump to

Keyboard shortcuts

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