activity

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package activity provides a small in-process pub/sub hub for qui-owned server events ("server activity"). Background services publish lightweight signals when their state changes; the SSE layer subscribes and forwards them to connected browsers, which invalidate the matching cached query and refetch on demand instead of polling on a timer.

Events are deliberately signals, not data: they carry identifiers only (kind, instance id, resource id), never payloads. A dropped event is therefore safe - the next event, a stream reconnect, or a low-rate safety refetch reconciles the client - so the hub favours never blocking a publisher over guaranteed delivery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Kind       Kind      `json:"kind"`
	InstanceID int       `json:"instanceId,omitempty"`
	ResourceID string    `json:"resourceId,omitempty"`
	Timestamp  time.Time `json:"timestamp"`
}

Event is a small, JSON-serializable signal that some qui-owned state changed. InstanceID and ResourceID are optional and scope the invalidation when set.

type Hub

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

Hub fans out published events to all current subscribers. The zero value is not usable; construct with NewHub.

func NewHub

func NewHub() *Hub

NewHub returns a ready-to-use Hub.

func (*Hub) Close

func (h *Hub) Close()

Close shuts the hub down, closing all subscriber channels. Subsequent Publish/Subscribe calls are no-ops.

func (*Hub) Dropped

func (h *Hub) Dropped() uint64

Dropped reports the lifetime count of events dropped due to full subscriber buffers.

func (*Hub) Publish

func (h *Hub) Publish(ev Event)

Publish delivers ev to every subscriber without blocking. A subscriber whose buffer is full has the event dropped (counted via Dropped).

func (*Hub) Subscribe

func (h *Hub) Subscribe() (<-chan Event, func())

Subscribe registers a new subscriber and returns its receive channel plus an idempotent unsubscribe func. The channel is closed on unsubscribe or Close.

type Kind

type Kind string

Kind identifies the category of a server activity event. The frontend maps each kind to the react-query keys it should invalidate.

const (
	KindBackupRun          Kind = "backup.run"
	KindDirScanRun         Kind = "dirscan.run"
	KindOrphanScanRun      Kind = "orphanscan.run"
	KindCrossSeedStatus    Kind = "crossseed.status"
	KindCrossSeedSearch    Kind = "crossseed.search"
	KindReannounceActivity Kind = "reannounce.activity"
	KindAutomationActivity Kind = "automation.activity"
	KindIndexerActivity    Kind = "indexer.activity"
	KindSearchHistory      Kind = "search.history"
	KindTrackerIcons       Kind = "tracker.icons"
)

type NopPublisher

type NopPublisher struct{}

NopPublisher is a no-op Publisher used as the default so services run normally when no hub is wired (e.g. in tests).

func (NopPublisher) Publish

func (NopPublisher) Publish(Event)

Publish discards the event.

type Publisher

type Publisher interface {
	Publish(ev Event)
}

Publisher is the write side that background services depend on. Implementations must return quickly and never block the caller.

Jump to

Keyboard shortcuts

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