activity

package
v0.0.0-...-d771ed5 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package activity provides a persistent activity log that records events from the in-memory event bus so they survive restarts and are queryable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidCategory

func ValidCategory(c string) bool

ValidCategory reports whether c is one of the closed-set categories or a legacy value the API still accepts.

Types

type Activity

type Activity struct {
	ID        string         `json:"id"`
	Type      string         `json:"type"`
	Category  string         `json:"category"`
	SeriesID  *string        `json:"series_id,omitempty"`
	Title     string         `json:"title"`
	Detail    map[string]any `json:"detail,omitempty"`
	CreatedAt string         `json:"created_at"`
}

Activity is the domain representation of an activity log entry.

type AttentionItem

type AttentionItem struct {
	// Kind is one of "grab_failed", "import_failed", "stalled".
	Kind string `json:"kind"`
	// GrabID is set for grab/stall items; empty for import-only failures.
	GrabID       string `json:"grab_id,omitempty"`
	SeriesID     string `json:"series_id,omitempty"`
	EpisodeID    string `json:"episode_id,omitempty"`
	ReleaseTitle string `json:"release_title"`
	Detail       string `json:"detail,omitempty"`
	// InfoHash lets the UI deep-link "open in Haul" for stalled items.
	InfoHash  string `json:"info_hash,omitempty"`
	CreatedAt string `json:"created_at"`
}

AttentionItem is a single row in the "Needs attention" rail.

type AttentionResult

type AttentionResult struct {
	Items []AttentionItem `json:"items"`
	// Counts breaks the items down by kind so the UI can show a summary
	// without re-counting client-side.
	Counts struct {
		GrabFailed   int `json:"grab_failed"`
		ImportFailed int `json:"import_failed"`
		Stalled      int `json:"stalled"`
	} `json:"counts"`
}

AttentionResult is the response shape for /api/v1/activity/needs-attention.

type Category

type Category string

Category groups related event types for filtering. The set is closed — every row in activity_log.category should be one of these constants. The frontend's Activity-page "Needs attention" rail filters on the failure variants; renaming or removing a constant means coordinating a migration AND a frontend update at the same time.

Mirrored in:

  • internal/db/migrations/00009_activity_categories.sql (back-fill)
  • web/ui/src/api/activity.ts (TypeScript union type)
  • web/ui/src/pages/activity/categories.ts (display labels)
const (
	// Grabs.
	CategoryGrabSucceeded Category = "grab_succeeded"
	CategoryGrabFailed    Category = "grab_failed"

	// Imports.
	CategoryImportSucceeded Category = "import_succeeded"
	CategoryImportFailed    Category = "import_failed"

	// Stalled grabs (Pilot-side classification of Haul stall reports).
	CategoryStalled Category = "stalled"

	// Library mutations.
	CategoryShow Category = "show"

	// Reserved — no emitter today, but kept so the migration is forward-only
	// when a task tracker / health emitter is wired up.
	CategoryTask   Category = "task"
	CategoryHealth Category = "health"
)

func AllCategories

func AllCategories() []Category

AllCategories returns the canonical (post-migration) category values. Used by the API handler's docstring and (indirectly) the frontend command-palette suggestions.

type ListResult

type ListResult struct {
	Activities []Activity `json:"activities"`
	Total      int64      `json:"total"`
}

ListResult is the paginated response from List.

type Service

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

Service records and queries activity log entries.

func NewService

func NewService(q db.Querier, logger *slog.Logger) *Service

NewService creates a new activity service.

func (*Service) List

func (s *Service) List(ctx context.Context, category *string, since *string, limit int64) (*ListResult, error)

List returns activity entries matching the given filters.

func (*Service) NeedsAttention

func (s *Service) NeedsAttention(ctx context.Context, window time.Duration, perKind int) (*AttentionResult, error)

NeedsAttention returns recent failures and stalls for the Activity-page "Needs attention" rail. window controls how far back to look; perKind caps each bucket so a flood of one type doesn't drown out the others.

func (*Service) Prune

func (s *Service) Prune(ctx context.Context, olderThan time.Duration) error

Prune deletes activity entries older than the given duration.

func (*Service) Subscribe

func (s *Service) Subscribe(bus *events.Bus)

Subscribe registers the service as an event bus handler. Call this once during startup after constructing the service.

Jump to

Keyboard shortcuts

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