daemon

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(opts Options) error

Run starts the daemon and blocks until shutdown.

func WaitForShutdown

func WaitForShutdown() <-chan os.Signal

WaitForShutdown returns a channel that fires on SIGINT/SIGTERM.

Types

type Builder

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

Builder manages the full build and incremental update pipeline.

func NewBuilder

func NewBuilder(opts BuilderOptions) *Builder

NewBuilder creates a new Builder.

func (*Builder) FullBuild

func (b *Builder) FullBuild(ctx context.Context) error

FullBuild runs the complete 8-stage build pipeline. Uses the serialized build queue to prevent concurrent builds.

func (*Builder) HandleContentChanged

func (b *Builder) HandleContentChanged(ctx context.Context, event eventbus.Event) error

HandleContentChanged is called when content changes are detected.

func (*Builder) IncrementalBuild

func (b *Builder) IncrementalBuild(ctx context.Context, changedFiles []string) error

IncrementalBuild rebuilds only the pages affected by the given file changes. It uses the DAG to determine affected pages and build.IncrementalRender to re-render only those pages, reusing the cached pipeline state.

Falls back to a full build when:

  • a template/i18n/config/theme file changed (cache invalid)
  • no PipelineCache is available
  • the DAG is empty (no prior full build)

func (*Builder) QueueBuild

func (b *Builder) QueueBuild(ctx context.Context, buildFn func() error) error

QueueBuild ensures only one build runs at a time. If a build is in progress, it marks pending and returns (the running build will trigger a trailing rebuild). This coalesces multiple concurrent change events into a single rebuild.

func (*Builder) RenderPageJIT

func (b *Builder) RenderPageJIT(ctx context.Context, pageURL string) (string, error)

RenderPageJIT renders a single page on demand for JIT fallback. Reuses the cached pipeline state for speed. Returns the HTML (not written to disk); the caller (serving.jitFallback) caches it in JITCache.

Tries the fast path (JITRenderFast) first for regular pages: loads only the target page, renders only its markdown, and builds only its context. Falls back to the full RenderPageWithCache for list pages or when the cache is not yet populated.

Returns an error (→ 404 in serving layer) when the source file cannot be resolved or does not exist on disk.

func (*Builder) TriggerRebuild

func (b *Builder) TriggerRebuild()

TriggerRebuild is an external trigger (from Admin API) to rebuild.

type BuilderOptions

type BuilderOptions struct {
	SourceDir   string
	OutputDir   string
	Bus         eventbus.EventBus
	DAG         *dag.DependencyGraph
	JITCache    *cache.JITCache
	Metrics     *MetricsCollector
	BuildDrafts bool
	Logf        func(format string, args ...any)

	// OnAfterBuild is called after a successful full build completes.
	// This is separate from the build's AfterBuild which captures the RenderPageFunc.
	OnAfterBuild func(*build.Result) error

	// PipelineCache holds reusable build state for incremental builds.
	// Populated after the first full build (via build.Options.PipelineCache).
	// When nil, IncrementalBuild falls back to a full build.
	PipelineCache *build.PipelineCache

	// ContentIndex is reloaded from <OutputDir>/api/*.json after each build
	// so the /api/v1/* query API serves fresh data. Optional: when nil, the
	// reload hook is skipped.
	ContentIndex *contentindex.ContentIndex

	// ThemeManager, if non-nil, is passed to build.Options.ThemeManager
	// for full builds, incremental builds, and JIT rendering.
	ThemeManager *theme.Manager
}

BuilderOptions configures the Builder.

type Daemon

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

Daemon holds the long-running server state.

type HealthChecker

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

HealthChecker provides health check endpoint.

func NewHealthChecker

func NewHealthChecker() *HealthChecker

NewHealthChecker creates a HealthChecker.

func (*HealthChecker) Handler

func (h *HealthChecker) Handler() http.HandlerFunc

Handler returns the HTTP handler for health checks.

func (*HealthChecker) SetReady

func (h *HealthChecker) SetReady(ready bool)

SetReady marks the daemon as ready to serve traffic.

type MetricsCollector

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

MetricsCollector tracks build and request metrics via Prometheus.

func NewMetricsCollector

func NewMetricsCollector() *MetricsCollector

NewMetricsCollector creates a MetricsCollector with registered Prometheus metrics.

func (*MetricsCollector) Handler

func (m *MetricsCollector) Handler() http.Handler

Handler returns the Prometheus metrics endpoint.

func (*MetricsCollector) RecordBuild

func (m *MetricsCollector) RecordBuild(duration time.Duration)

RecordBuild records a successful build.

func (*MetricsCollector) RecordBuildFailure

func (m *MetricsCollector) RecordBuildFailure()

RecordBuildFailure records a failed build.

func (*MetricsCollector) RecordCacheHit

func (m *MetricsCollector) RecordCacheHit()

RecordCacheHit records a JIT cache hit.

func (*MetricsCollector) RecordCacheMiss

func (m *MetricsCollector) RecordCacheMiss()

RecordCacheMiss records a JIT cache miss.

func (*MetricsCollector) RecordRequest

func (m *MetricsCollector) RecordRequest(method, path string, duration time.Duration)

RecordRequest records an HTTP request.

type Options

type Options struct {
	SourceDir      string
	ConfigPath     string // daemon.yaml path, optional
	Port           string
	Bind           string
	TLSCert        string
	TLSKey         string
	Systemd        bool
	BuildDrafts    bool
	DisableWatch   bool             // disable file watching (default false)
	BuildInterval  time.Duration    // periodic full rebuild interval (0 = disabled)
	PluginDir      string           // plugin directory (default: <sourceDir>/plugins)
	DisablePlugin  bool             // disable plugin loading
	PluginRegistry *plugin.Registry // compiled plugins registry (optional)
	ThemeManager   *theme.Manager   // theme manager (optional)
}

Options configures the daemon.

type Serving

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

Serving manages the HTTP server, static file serving, JIT rendering, and admin API.

func NewServing

func NewServing(opts ServingOptions) *Serving

NewServing creates a new Serving instance.

func (*Serving) HandleCacheUpdated

func (s *Serving) HandleCacheUpdated(ctx context.Context, event eventbus.Event) error

HandleCacheUpdated is called when the cache is updated.

func (*Serving) Shutdown

func (s *Serving) Shutdown(ctx context.Context) error

Shutdown gracefully stops the HTTP server.

func (*Serving) Start

func (s *Serving) Start(ctx context.Context) error

Start begins the HTTP server and blocks.

type ServingOptions

type ServingOptions struct {
	OutputDir    string
	Bind         string
	Port         string
	TLSCert      string
	TLSKey       string
	AdminHandler http.Handler
	JITCache     *cache.JITCache
	Builder      *Builder
	Bus          eventbus.EventBus
	Logf         func(format string, args ...any)
	Health       *HealthChecker
	Metrics      *MetricsCollector

	// ContentAPI is an optional read-only handler for /api/v1/* content
	// queries. When non-nil, it is registered before the / catch-all so
	// exact-prefix matches win over the static file fallback.
	ContentAPI http.Handler

	// SSEHub, if non-nil, enables the /api/v1/events real-time push endpoint.
	SSEHub *sse.SSEHub
}

ServingOptions configures the Serving layer.

type SystemdNotifier

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

SystemdNotifier integrates with systemd's sd_notify protocol. Phase 1: basic support. Phase 2: full sd_notify implementation.

func NewSystemdNotifier

func NewSystemdNotifier(enabled bool) *SystemdNotifier

NewSystemdNotifier creates a SystemdNotifier. If enabled is true and NOTIFY_SOCKET env var is set, notifications are sent.

func (*SystemdNotifier) Ready

func (n *SystemdNotifier) Ready()

Ready sends READY=1 to systemd.

func (*SystemdNotifier) Status

func (n *SystemdNotifier) Status(msg string)

Status sends a status message to systemd.

func (*SystemdNotifier) Stopping

func (n *SystemdNotifier) Stopping()

Stopping sends STOPPING=1 to systemd.

type Watcher

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

Watcher watches content/ and data/ for changes, then triggers rebuild.

func NewWatcher

func NewWatcher(opts WatcherOptions) (*Watcher, error)

NewWatcher creates a new Watcher that recursively watches SourceDir.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

Run starts the watcher event loop. Blocks until ctx is cancelled or watcher encounters a fatal error.

type WatcherOptions

type WatcherOptions struct {
	SourceDir string
	Debounce  time.Duration               // default 400ms
	OnChange  func(changedFiles []string) // called with list of changed files after debounce
	Logf      func(format string, args ...any)
}

WatcherOptions configures the daemon's file watcher.

Directories

Path Synopsis
Package contentindex provides an in-memory query index over the pre-built /api/{section}.json files.
Package contentindex provides an in-memory query index over the pre-built /api/{section}.json files.
Package sse provides Server-Sent Events (SSE) push for the daemon.
Package sse provides Server-Sent Events (SSE) push for the daemon.

Jump to

Keyboard shortcuts

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