completer

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package completer writes job completions and heartbeats to the database in batches.

Index

Constants

View Source
const (
	DefaultBatchSize     = 100
	DefaultFlushInterval = 50 * time.Millisecond
	DefaultBufferSize    = 10_000
	DefaultMaxRetryDelay = 5 * time.Second
	DefaultFlushTimeout  = 10 * time.Second
	DefaultCallTimeout   = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Completer

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

Completer batches job completions into single statements and retries them on database errors.

func New

func New(cfg Config) (*Completer, error)

New validates cfg and applies defaults.

func (*Completer) Add

func (c *Completer) Add(comp job.Completion)

Add queues one completion for the next batch.

func (*Completer) Full

func (c *Completer) Full() bool

func (*Completer) Len

func (c *Completer) Len() int

func (*Completer) Run

func (c *Completer) Run(ctx context.Context) error

Run writes batches until ctx is cancelled, then flushes what is left.

type Config

type Config struct {
	ClientID      string
	Store         job.CompletionWriter
	Clock         clock.Clock
	Logger        *slog.Logger
	BatchSize     int
	FlushInterval time.Duration
	BufferSize    int
	MaxRetryDelay time.Duration
	FlushTimeout  time.Duration
	CallTimeout   time.Duration
	OnApplied     func(applied []job.Completion, stale int)
	OnDrained     func()
	Rand          func() float64
}

type HeartbeatConfig

type HeartbeatConfig struct {
	ClientID string
	Store    job.HeartbeatWriter
	Clock    clock.Clock
	Logger   *slog.Logger
	Interval time.Duration
	Running  func() []job.Ref
}

type Heartbeater

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

Heartbeater refreshes the heartbeat of this client's running jobs every Interval.

func NewHeartbeater

func NewHeartbeater(cfg HeartbeatConfig) (*Heartbeater, error)

NewHeartbeater validates cfg and applies defaults.

func (*Heartbeater) Beat

func (h *Heartbeater) Beat(ctx context.Context, ref job.Ref) error

Beat refreshes the heartbeat of one job now.

func (*Heartbeater) Run

func (h *Heartbeater) Run(ctx context.Context) error

Run sends heartbeats until ctx is cancelled.

Jump to

Keyboard shortcuts

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