activity

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package activity persists bus lifecycle events into the torrent_events table so the Activity page can render a full history (across restarts) instead of just the in-memory live stream.

What gets persisted: every event with an InfoHash, except the high-frequency health_update telemetry. The noise type is filtered here, not at the bus, since the live websocket stream still needs it for the dashboard gauges.

Failures are logged and swallowed — losing one row of activity history is not worth crashing a download for.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventRow

type EventRow struct {
	ID         int64  `json:"id"`
	InfoHash   string `json:"info_hash"`
	EventType  string `json:"event_type"`
	OccurredAt string `json:"occurred_at"` // RFC3339
	Payload    any    `json:"payload"`
}

EventRow is a single row from the per-torrent event timeline. The payload column is delivered as raw JSON so the frontend can render whatever shape the producer emitted without us needing to model every event type.

func ListEvents

func ListEvents(ctx context.Context, db *sql.DB, infoHash string, limit int) ([]EventRow, error)

ListEvents returns the event timeline for one torrent, newest first.

type Item

type Item struct {
	InfoHash    string `json:"info_hash"`
	Name        string `json:"name"`
	Category    string `json:"category"`
	SavePath    string `json:"save_path"`
	SizeBytes   int64  `json:"size_bytes"`
	Resolution  string `json:"resolution"`
	AddedAt     string `json:"added_at"`               // RFC3339
	CompletedAt string `json:"completed_at,omitempty"` // empty if still in progress
	RemovedAt   string `json:"removed_at,omitempty"`   // empty if still active

	Requester string `json:"requester,omitempty"`
	MovieID   string `json:"movie_id,omitempty"`
	SeriesID  string `json:"series_id,omitempty"`
	EpisodeID string `json:"episode_id,omitempty"`
	TMDBID    int    `json:"tmdb_id,omitempty"`
	Season    int    `json:"season,omitempty"`
	Episode   int    `json:"episode,omitempty"`
}

Item is a single row in the activity list. One row per torrent, including those that have been completed or removed — the table is the full history.

func List

func List(ctx context.Context, db *sql.DB, f ListFilter) ([]Item, int64, error)

List runs the activity list query and returns rows + total match count. Returns an empty slice (not an error) when nothing matches.

type ListFilter

type ListFilter struct {
	Search string // free-text matched against name + category (ILIKE)
	Status string // "active" | "completed" | "removed" | "all" (default "all")
	Sort   string // "added_at" (default) | "completed_at" | "removed_at" | "size_bytes" | "resolution" | "name"
	Order  string // "asc" | "desc" (default "desc")
	Limit  int    // default 50, cap 200
	Offset int
}

ListFilter scopes a List query.

type Persister

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

Persister is a bus subscriber that writes lifecycle events to the torrent_events table.

func NewPersister

func NewPersister(db *sql.DB, logger *slog.Logger) *Persister

NewPersister builds a Persister. Pass the result of its HandleEvent method to bus.Subscribe.

func (*Persister) HandleEvent

func (p *Persister) HandleEvent(ctx context.Context, e events.Event)

HandleEvent is the bus subscriber callback. Drops noisy types and events without an InfoHash (those are not torrent-scoped — e.g. session-wide health pings).

Jump to

Keyboard shortcuts

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