dbwatch

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dbwatch - whether the site's database answers: a loop pinging it, so the requests and the background work learn it is gone at once instead of each waiting for a connection that doesn't come.

Index

Constants

View Source
const (
	// Interval - how often the database is pinged.
	Interval = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Watch

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

Watch - whether the database answers (Down), from a ping every Interval (Start). A nil Watch - the database is never down.

func New

func New(ping func(context.Context) error, logger *slog.Logger) *Watch

New - a watch pinging the database with ping, telling logger when it goes and comes back.

func (*Watch) Check

func (w *Watch) Check(ctx context.Context)

Check pings the database once: failuresDown failures in a row make it down, an answer up again. Both changes are logged - here, the loop has nobody to return them to.

func (*Watch) Done

func (w *Watch) Done() <-chan struct{}

Done - closed once the loop Start began has returned.

func (*Watch) Down

func (w *Watch) Down() bool

Down - the database doesn't answer: its last pings failed.

func (*Watch) Start

func (w *Watch) Start(ctx context.Context)

Start pings the database every Interval until ctx ends (Done).

Jump to

Keyboard shortcuts

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