activity

package
v0.13.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: 9 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 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 returns true if c is a known category.

Types

type Activity

type Activity struct {
	ID        string         `json:"id"`
	Type      string         `json:"type"`
	Category  string         `json:"category"`
	MovieID   *string        `json:"movie_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         string `json:"kind"` // "grab_failed" | "import_failed"
	GrabID       string `json:"grab_id,omitempty"`
	MovieID      string `json:"movie_id,omitempty"`
	ReleaseTitle string `json:"release_title"`
	Detail       string `json:"detail,omitempty"`
	CreatedAt    string `json:"created_at"`
}

AttentionItem is one entry in the "Needs attention" rail. Each item is either a failed or removed grab (from grab_history.download_status) or a failed import (from activity_log.category=import_failed).

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"`
	} `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. Mirrors Pilot's success/failure split so the Activity-page "Needs attention" rail can find failed grabs/imports without re-parsing the type column.

const (
	CategoryGrabSucceeded   Category = "grab_succeeded"
	CategoryGrabFailed      Category = "grab_failed"
	CategoryImportSucceeded Category = "import_succeeded"
	CategoryImportFailed    Category = "import_failed"
	CategoryTask            Category = "task"
	CategoryHealth          Category = "health"
	CategoryMovie           Category = "movie"

	// Legacy values kept in the validator so existing API clients that
	// filter by the old coarse names ("grab"/"import") don't break.
	// Migration 00005_activity_categories.sql back-fills DB rows to
	// the new vocabulary; these constants exist only to accept legacy
	// query strings.
	CategoryGrabLegacy   Category = "grab"
	CategoryImportLegacy Category = "import"
)

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 dbgen.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 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.

Mirrors Pilot's NeedsAttention shape (see pilot/internal/core/activity /service.go) — minus the "stalled" bucket, which Prism doesn't have a stallwatcher for. Add stalled here if/when one ships.

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