aggregator

package
v0.0.0-...-e083d15 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package aggregator provides persistent storage and periodic snapshotting of aggregated analytics stats to PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store persists aggregated analytics snapshots in PostgreSQL.

It requires an `analytics_snapshots` table:

CREATE TABLE analytics_snapshots (
    id         BIGSERIAL PRIMARY KEY,
    data       JSONB NOT NULL,
    captured_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

func NewStore

func NewStore(db *postgres.Client) *Store

NewStore creates a new analytics persistence store.

func (*Store) LatestSnapshot

func (s *Store) LatestSnapshot(ctx context.Context) (*analytics.AggregatedStats, error)

LatestSnapshot loads the most recent snapshot from the database. Returns nil, nil if no snapshots exist yet.

func (*Store) ListSnapshots

func (s *Store) ListSnapshots(ctx context.Context, limit int) ([]analytics.AggregatedStats, error)

ListSnapshots returns the last N snapshots, newest first.

func (*Store) SaveSnapshot

func (s *Store) SaveSnapshot(ctx context.Context, stats analytics.AggregatedStats) error

SaveSnapshot persists a stats snapshot to the database.

func (*Store) StartPeriodicSave

func (s *Store) StartPeriodicSave(ctx context.Context, agg *analytics.Aggregator, interval time.Duration)

StartPeriodicSave launches a goroutine that periodically snapshots the aggregator's current stats to the database.

Jump to

Keyboard shortcuts

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