rselection

package
v3.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 7 Imported by: 0

README

pkg/rselection

A lightweight leader election library intended for use with rsnotify. Provides an implementation for Postgresql (using pgx). Also provides an implementation for single-node use where we assume the single node is always the leader.

Provides interfaces for scheduled and persistent tasks that are run on an active leader node.

Documentation

Index

Constants

View Source
const (
	TaskTypePersistent uint8 = 0
	TaskTypeScheduled  uint8 = 1

	ScheduleTypeInterval uint8 = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GenericTask

type GenericTask struct {
	TaskName     string
	TaskType     uint8
	TaskSchedule Schedule
}

func (*GenericTask) Name

func (t *GenericTask) Name() string

func (*GenericTask) Schedule

func (t *GenericTask) Schedule() Schedule

func (*GenericTask) Type

func (t *GenericTask) Type() uint8

type GenericTaskHandler

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

func (*GenericTaskHandler) Handle

func (*GenericTaskHandler) Register

func (h *GenericTaskHandler) Register(name string, task Task)

Register adds a task to the handler. It must be called before Handle(). Calling Register after Handle() or registering the same task name twice will cause the program to exit via log.Fatalf.

func (*GenericTaskHandler) Stop

func (h *GenericTaskHandler) Stop()

func (*GenericTaskHandler) Verify

func (h *GenericTaskHandler) Verify() <-chan chan bool

type GenericTaskHandlerConfig

type GenericTaskHandlerConfig struct {
}

type IntervalSchedule

type IntervalSchedule struct {
	Ticker <-chan time.Time
}

func (*IntervalSchedule) Next

func (c *IntervalSchedule) Next() <-chan time.Time

func (*IntervalSchedule) Type

func (*IntervalSchedule) Type() uint8

type Leader

type Leader interface {
	Lead() error
}

type Schedule

type Schedule interface {
	Type() uint8
	Next() <-chan time.Time
}

type Task

type Task interface {
	Name() string
	Type() uint8
	Schedule() Schedule
	Run(ctx context.Context, b broadcaster.Broadcaster)
}

type TaskHandler

type TaskHandler interface {
	Handle(b broadcaster.Broadcaster)
	Register(name string, task Task)
	Stop()
	Verify() <-chan chan bool
}

A TaskHandler runs in the context of a Leader Loop. When the leader loop ends, the TaskHandler stops. A TaskHandler can do two types of work:

  • Persistent jobs that run for the duration of the TaskHandler's run loop. Persistent jobs, for instance, can monitor a channel and track heartbeats for macro transactions or in-progress queue work.
  • Scheduled jobs that run periodically. Scheduled jobs have a set schedule and run per that schedule during the lifetime of the TaskHandler's run loop.

Directories

Path Synopsis
impls
pgx

Jump to

Keyboard shortcuts

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