background

package
v0.7.0-preview1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateLockID

func GenerateLockID(name string) int64

GenerateLockID creates a deterministic int64 lock ID from a task name using FNV-64a hash.

Types

type SingletonConfig

type SingletonConfig struct {
	// Name identifies the task (used for logging and lock ID generation).
	Name string
	// DB is the PostgreSQL connection pool.
	DB *pgxpool.Pool
	// Interval is the time between executions.
	Interval time.Duration
	// InitialDelay is an optional delay before the first execution.
	InitialDelay time.Duration
	// TaskFn is the function to execute on each tick.
	TaskFn TaskFunc
}

SingletonConfig configures a SingletonTask.

type SingletonTask

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

SingletonTask runs a periodic function protected by a PostgreSQL advisory lock. Only one instance across the cluster will execute the task at any given interval.

func NewSingletonTask

func NewSingletonTask(config SingletonConfig) *SingletonTask

NewSingletonTask creates a new singleton task.

func (*SingletonTask) Start

func (t *SingletonTask) Start(ctx context.Context)

Start begins the periodic execution loop.

func (*SingletonTask) Stop

func (t *SingletonTask) Stop()

Stop gracefully shuts down the task.

type TaskFunc

type TaskFunc func(ctx context.Context) error

TaskFunc is the function signature for a singleton task.

Jump to

Keyboard shortcuts

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