agent

package
v0.0.56 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

README

api/sinks/postgres/agent

Database functions used exclusively by the agent-facing API routes. Two operations are covered: submitting a completed check result, and pulling a random credential for a given team and userlist.

Score submission is the most critical write path in the system. It runs as a single transaction across the full historical scores table (append-only) and the recent scores table (one row per team/box/service combination, upserted to always reflect the latest result). Inside that same transaction it reads the current scoring-pause state, and only when scoring is running does it also increment the running total and passed counters in the final scores table. The check pause is not consulted here at all — it stops work from being dispatched in the first place, so a result arriving on this path is one that was meant to run. The effect is that a check submitted during a pause is still archived and still shown as the current status, but costs a team nothing in uptime. Reading the pause state inside the transaction rather than before it means the state cannot change between the decision and the write. All writes succeed or none do.

Credential lookup selects a random row from the scoring users table for the requested team and userlist. No validation is performed on the input; callers are expected to have already confirmed the userlist exists before calling.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddScore

func AddScore(ctx context.Context, db *pgxpool.Pool, score types.Score) error

AddScore inserts a score into the main score database. It also updates the entry for this specific box/service/team combo in the recent scores table.

func GetRandomUser

func GetRandomUser(
	ctx context.Context,
	db *pgxpool.Pool,
	userListID types.UserListName,
	teamNum types.TeamNum,
) (types.User, error)

GetRandomUser pulls a random user from a specific userlist for a specific team. This performs no validation. Will fail with an error if invalid input is given.

Types

This section is empty.

Jump to

Keyboard shortcuts

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