trigger

package
v0.101.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package trigger notifies downstream rebuild machinery that grains changed: after a publish, something must re-run serialize/project/index and redeploy the static site. The Notifier seam keeps that transport pluggable -- a webhook toward any CI system here, SQS/EventBridge in trigger/awstrigger -- and noop for setups that rebuild on a schedule.

Index

Constants

View Source
const SignatureHeader = "X-Lcat-Signature"

SignatureHeader carries the webhook body's HMAC-SHA256 (hex).

Variables

This section is empty.

Functions

func Sign

func Sign(secret, body []byte) string

Sign returns the hex HMAC-SHA256 of body under secret.

func Verify

func Verify(secret, body []byte, signature string) bool

Verify checks a webhook body against its signature header value.

Types

type Coalesce

type Coalesce struct {
	Next Notifier
	// Window is the quiet period that closes a batch. Default 5s.
	Window time.Duration
	// MaxDelay bounds how long a busy stream can hold the batch open,
	// measured from its first event. Default 12x Window.
	MaxDelay time.Duration
	// Timeout bounds one downstream delivery. Default 10 minutes.
	Timeout time.Duration
	Logger  *slog.Logger
	// contains filtered or unexported fields
}

Coalesce batches a burst of events into one downstream Notify carrying the union of changed paths (tasks/159): an editing session's stream of publishes becomes one incremental rebuild instead of one per save. The batch fires after Window of quiet, or MaxDelay after its first event, whichever comes first. Notify itself never blocks on the downstream -- delivery runs on its own goroutine with its own deadline, and a failure is logged, not returned, because the publish that triggered it has already succeeded (scheduled full rebuilds stay the correctness backstop).

func (*Coalesce) Notify

func (c *Coalesce) Notify(_ context.Context, e Event) error

Notify implements Notifier: it buffers the event and (re)arms the flush timer. Always returns nil; delivery is asynchronous.

type Command

type Command struct {
	// Shell command, run via sh -c.
	Cmd string
	// Dir is the working directory ("" = inherited).
	Dir string
	// Timeout bounds one run. Default 5 minutes.
	Timeout time.Duration
	// Logger receives run results. nil disables logging.
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Command runs a shell command on every event -- the local dev loop: point it at "lcat serialize && lcat project" targeting a running `hugo server`'s data directory and published edits appear in the discovery site within seconds, no cloud, no CI (the hugo-watcher idea from tasks/054). The changed blob paths arrive newline-joined in $LCAT_CHANGED_PATHS.

func (*Command) Notify

func (c *Command) Notify(ctx context.Context, e Event) error

Notify implements Notifier.

type Event

type Event struct {
	// Kind is the event class, e.g. "grains-changed".
	Kind string `json:"kind"`
	// Paths lists the changed blob paths (grain files).
	Paths []string  `json:"paths"`
	At    time.Time `json:"at"`
}

Event describes one batch of grain changes.

type Fanout

type Fanout []Notifier

Fanout delivers each event to every notifier, returning the first error after all have run (a failing webhook must not starve the local rebuild).

func (Fanout) Notify

func (f Fanout) Notify(ctx context.Context, e Event) error

Notify implements Notifier.

type Noop

type Noop struct{}

Noop discards events (scheduled-rebuild deployments).

func (Noop) Notify

func (Noop) Notify(context.Context, Event) error

Notify implements Notifier.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, e Event) error
}

Notifier delivers events to the rebuild pipeline.

type Webhook

type Webhook struct {
	URL    string
	Secret []byte
	// Client overrides the HTTP client (tests). nil = http.DefaultClient.
	Client *http.Client
}

Webhook POSTs each event as JSON to a URL, signed with an HMAC so the receiver can authenticate the sender (CI webhook endpoints are otherwise unauthenticated).

func (Webhook) Notify

func (w Webhook) Notify(ctx context.Context, e Event) error

Notify implements Notifier.

Directories

Path Synopsis
Package awstrigger delivers trigger events over AWS messaging: an SQS queue (a worker consumes and rebuilds) or an EventBridge bus (fan-out to CodeBuild/Step Functions).
Package awstrigger delivers trigger events over AWS messaging: an SQS queue (a worker consumes and rebuilds) or an EventBridge bus (fan-out to CodeBuild/Step Functions).

Jump to

Keyboard shortcuts

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