hooks

package
v0.0.86 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package hooks implements the Hook dispatcher. It subscribes to the Event Bus and delivers events to registered external hooks via batched HTTP webhook OR per-event JSON-lines file — asynchronously.

Per-protocol delivery shape:

  • HTTP: events buffered into a per-hook batcher; flushed when the batch hits BatchMaxItems OR when the BatchFlushIntervalSec timer fires. Failed batches re-queue at the front for the next flush. The queue is bounded by BatchMaxQueueItems — older events drop on overflow.

  • File: each event appended as a single JSON line. No batching — log shippers (Filebeat / Vector / Promtail) tail one line at a time.

Index

Constants

This section is empty.

Variables

View Source
var ErrHookTestUnsupported = errors.New("hooks: test delivery not supported for this hook type")

ErrHookTestUnsupported is returned when the hook type cannot receive a synthetic test delivery.

Functions

This section is empty.

Types

type Service

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

Service subscribes to the event bus and dispatches events to registered hooks.

HTTP hooks share an http.Client and route through per-hook batchers. File hooks share a per-target write mutex map so concurrent deliveries to the same path serialise without interleaving partial JSON lines.

func New

func New(i do.Injector) (*Service, error)

New creates a Service and registers it with the DI injector.

func (*Service) DeliverTestEvent

func (s *Service) DeliverTestEvent(ctx context.Context, id domain.HookID) error

DeliverTestEvent sends a single synthetic event to the hook using the same path as live delivery. For HTTP hooks the test event is enqueued into the batcher and shipped on the next flush — typically within a second when BatchFlushIntervalSec is 5 and the queue is otherwise empty (the test event triggers a size-1 batch only if BatchMaxItems=1).

To make tests visible quickly without forcing the operator to set BatchMaxItems=1, we explicitly signal the batcher right after enqueuing. The signal is a no-op when MaxItems hasn't been reached, so production behaviour is unaffected.

func (*Service) Start

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

Start subscribes to all domain events and begins dispatching. It blocks until ctx is cancelled, then drains and stops every active HTTP batcher so buffered events get one final flush before exit.

Jump to

Keyboard shortcuts

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