worker

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(ctx context.Context, db *pgxpool.Pool, workerID, region string, concurrency int)

Register upserts the worker row and then loops sending heartbeats until ctx is cancelled. On clean shutdown it marks the worker as stopped.

Types

type CloudJobSource

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

CloudJobSource implements spec.JobSource against the platform Postgres DB. Workers claim Monitor rows using SELECT … FOR UPDATE SKIP LOCKED.

func NewCloudJobSource

func NewCloudJobSource(db *pgxpool.Pool, workerID string, leaseDuration time.Duration, batchSize int) *CloudJobSource

func (*CloudJobSource) Ack

func (s *CloudJobSource) Ack(ctx context.Context, lease spec.Lease, result spec.CheckResult) error

Ack commits a completed check: writes the result, updates Monitor status, advances nextCheckAt, clears the lease, and dispatches alerts on transitions.

func (*CloudJobSource) Heartbeat

func (s *CloudJobSource) Heartbeat(ctx context.Context, lease spec.Lease) error

Heartbeat extends the lease expiry to prevent expiration during long-running checks.

func (*CloudJobSource) Nack

func (s *CloudJobSource) Nack(ctx context.Context, lease spec.Lease, reason string) error

Nack releases the lease and applies a short backoff before retry.

func (*CloudJobSource) Poll

Poll claims up to batchSize due monitors and returns them as Leases.

type Pool

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

func NewPool

func NewPool(concurrency int, source spec.JobSource, onResult ResultHandler, leaseDuration time.Duration) *Pool

func (*Pool) Run

func (p *Pool) Run(ctx context.Context, leases <-chan spec.Lease)

type ResultHandler

type ResultHandler func(spec.CheckResult)

Jump to

Keyboard shortcuts

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