activityhandlers

package
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package activityhandlers serves the activity log, the alert list, and the SSE event stream: the HTTP surface over the three in-memory registries that record what the server is doing and what went wrong.

It exists because every other data package under internal/server acquired a handlers sibling — coverage has coveragehandlers, config has confighandlers — while activity and events did not, so six handlers over four fields stayed on Server. They were the narrowest cluster on that type: no live state, no store, no metrics, no config, and all four dependencies were already sub-package types. The package's own extraction criterion is that a concern moves out once it can be handed its dependencies rather than reaching for a snapshot, and this one never needed the snapshot at all.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	// Activity is the running/completed activity log this surface pages over.
	Activity *activity.Log
	// Alerts is the persistent-alert list the UI banner reads.
	Alerts *activity.AlertLog
	// Stops is the live stop-callback registry: it supplies the cancellable flag
	// on a running entry and receives the explicit stop request.
	Stops *activity.StopRegistry
	// Events is the SSE hub. The client cap lives on the hub itself, set at
	// construction and re-applied by hot reload, so no per-request config read
	// happens here.
	Events *events.EventBus
}

Deps is what this surface needs, and it is the whole of it: three registries and the event hub, each already owned by a sibling package.

Stops is a pointer because Server holds the registry by value and the scan and scheduler packages register into that same one — the registry's zero value is ready to use, so it lives as a field and is shared by address, the way a sync.WaitGroup is.

type Handler

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

Handler serves the activity, alert and event routes.

func New

func New(deps Deps) *Handler

New returns a Handler over deps.

func (*Handler) HandleCancelActivity

func (h *Handler) HandleCancelActivity(w http.ResponseWriter, r *http.Request)

HandleCancelActivity handles POST /api/activity/{id}/cancel — the explicit graceful stop for running background scans. The scan ends after the item in flight completes (a stop SIGNAL, never a context hard-kill).

Two idioms now address activity entries and must not be confused: DELETE /api/activity?id= (dismiss) removes a completed row or cancels a QUEUED one and never stops running work; this endpoint stops RUNNING work and nothing else.

Authorization is object-level against the entry's required role: per-item scans are cancellable by any configured user (single-household policy), full scans — manual and scheduled both run through the same path — by admins only. Responses: 204 stopped or already stopping (idempotent), 403 role too low, 404 unknown id, 409 not cancellable (completed, queued dismiss-cancelled, or not a stoppable activity). Every attempt is logged.

func (*Handler) HandleDismissActivity

func (h *Handler) HandleDismissActivity(w http.ResponseWriter, r *http.Request)

HandleDismissActivity removes a completed activity or cancels a queued one. DELETE /api/activity?id={id}

func (*Handler) HandleDismissAlert

func (h *Handler) HandleDismissAlert(w http.ResponseWriter, r *http.Request)

HandleDismissAlert handles DELETE /api/alerts?id=N.

func (*Handler) HandleEvents

func (h *Handler) HandleEvents(w http.ResponseWriter, r *http.Request)

HandleEvents serves the SSE stream.

func (*Handler) HandleGetActivity

func (h *Handler) HandleGetActivity(w http.ResponseWriter, _ *http.Request)

HandleGetActivity returns the most recent activity entries. Running entries survive the page cap unconditionally — a busy system must never hide a live cancellable scan, because UI restoration depends on seeing it — and each running entry carries the serialization-time cancellable flag merged from the stop registry.

func (*Handler) HandleGetAlerts

func (h *Handler) HandleGetAlerts(w http.ResponseWriter, _ *http.Request)

HandleGetAlerts handles GET /api/alerts. Method dispatch lives in routes.go (GET here, DELETE on HandleDismissAlert) like every other route.

Jump to

Keyboard shortcuts

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