pauses

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

README

api/sinks/postgres/pauses

Database functions that record and read whether the competition is currently paused. Pausing is durable rather than in-memory: the state lives in its own table and survives an API server restart, so an operator who pauses for a lunch break and then restarts the server does not silently resume. Other database subpackages and route handlers consult this state to decide whether work should be dispatched and whether a result should count toward a team's totals.

Two kinds of pause are tracked independently in the same table, distinguished by an enumerated type column. A scoring pause halts the accumulation of team totals while leaving checks running, and a check pause halts the checks themselves. Each kind carries its own current state and its own history, so the two can be toggled in any combination without one clobbering the other.

The table is an append-only log of state changes rather than a single mutable row. Each entry carries its pause kind, the new state, and the Unix microsecond timestamp at which it took effect; the current state for a kind is whichever of its entries has the newest timestamp. Keeping the history means the exact windows during which scoring or checking was halted remain queryable after the fact.

The package provides an initializer, a pair of single-state readers, a combined reader, and a state changer. The initializer seeds the configured starting state for both pause kinds, guarded per kind so that it writes only when that kind has no entry yet and is therefore a no-op on every boot after the first; it takes an advisory lock so that several API servers booting against one database cannot race each other into duplicate seeds. The two single-state readers differ only in what they read through: one takes the connection pool, for callers that only need an answer, and one takes a transaction, so that a caller writing scores can read the pause state and act on it inside the same transaction with no window in which the state could change underneath it. The combined reader returns both kinds at once along with the moment each was entered, for reporting to an operator. The state changer takes the advisory lock for the duration of its transaction, compares the requested state against the current one, writes nothing and reports no change when they already match, and otherwise appends a new entry.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangePauseState

func ChangePauseState(
	ctx context.Context,
	db *pgxpool.Pool,
	desiredState types.PauseState,
	desiredType types.PauseType,
) (changed bool, err error)

ChangePauseState pauses or unpauses the competition.

func GetPauseRecord

func GetPauseRecord(ctx context.Context, db *pgxpool.Pool) (types.PauseRecord, error)

GetPauseRecord returns the current pause state, as well as the time that state went into effect.

func InitPauses

func InitPauses(ctx context.Context, db *pgxpool.Pool, cfg *config.APIConfigSpec) error

InitPauses sets the pause state in the db to the configured default when none exists.

func IsPaused

func IsPaused(ctx context.Context, db *pgxpool.Pool, pauseType types.PauseType) (types.PauseState, error)

IsPaused returns whether or not the competition is currently paused. Takes a tx instead of the entire db pool for use in reliable logic.

func IsPausedTx

func IsPausedTx(ctx context.Context, tx pgx.Tx, pauseType types.PauseType) (types.PauseState, error)

IsPausedTx returns whether or not the competition is currently paused. Takes a tx instead of the entire db pool for use in reliable logic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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