Help us shape the future of Go! Take the 2026 Go Developer Survey

relayhook

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package relayhook bridges Dispatch lifecycle events to Relay for webhook delivery. When registered as an extension, it emits typed webhook events (dispatch.job.completed, dispatch.workflow.failed, etc.) at every lifecycle point.

Usage:

r, _ := relay.New(relay.WithStore(store))
relayhook.RegisterAll(ctx, r)

hook := relayhook.New(r)
engine.WithExtension(hook)

To restrict which events are emitted:

hook := relayhook.New(r,
    relayhook.WithEvents(
        relayhook.EventJobCompleted,
        relayhook.EventJobFailed,
    ),
)

Index

Constants

View Source
const (
	EventJobEnqueued           = "dispatch.job.enqueued"
	EventJobStarted            = "dispatch.job.started"
	EventJobCompleted          = "dispatch.job.completed"
	EventJobFailed             = "dispatch.job.failed"
	EventJobRetrying           = "dispatch.job.retrying"
	EventJobDLQ                = "dispatch.job.dlq"
	EventJobCancelled          = "dispatch.job.cancelled"
	EventWorkflowStarted       = "dispatch.workflow.started"
	EventWorkflowStepCompleted = "dispatch.workflow.step_completed"
	EventWorkflowStepFailed    = "dispatch.workflow.step_failed"
	EventWorkflowCompleted     = "dispatch.workflow.completed"
	EventWorkflowFailed        = "dispatch.workflow.failed"
	EventCronFired             = "dispatch.cron.fired"
)

Dispatch lifecycle event types. Each constant maps to one ext lifecycle hook and is used as the event.Event.Type when sending via Relay.

View Source
const (
	EventOperatorJobCancelled     = "dispatch.operator.job_cancelled"
	EventOperatorJobRetried       = "dispatch.operator.job_retried"
	EventOperatorDLQReplayed      = "dispatch.operator.dlq_replayed"
	EventOperatorDLQDeleted       = "dispatch.operator.dlq_deleted"
	EventOperatorDLQPurged        = "dispatch.operator.dlq_purged"
	EventOperatorCronEnabled      = "dispatch.operator.cron_enabled"
	EventOperatorCronDisabled     = "dispatch.operator.cron_disabled"
	EventOperatorCronDeleted      = "dispatch.operator.cron_deleted"
	EventOperatorCronTriggered    = "dispatch.operator.cron_triggered"
	EventOperatorWorkflowReplayed = "dispatch.operator.workflow_replayed"
)

Operator action event types. Each constant maps to one ext.ActionKind. They sit under dispatch.operator so a subscriber can tell an operator's cancel apart from the dispatch.job.cancelled lifecycle event it causes.

Variables

This section is empty.

Functions

func AllDefinitions

func AllDefinitions() []catalog.WebhookDefinition

AllDefinitions returns webhook definitions for all Dispatch lifecycle event types. Pass these to relay.RegisterEventType to populate the catalog.

func RegisterAll

func RegisterAll(ctx context.Context, r *relay.Relay) error

RegisterAll registers all Dispatch webhook event types in the Relay catalog. Call this once during application startup before sending events.

Types

type Extension

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

Extension bridges Dispatch lifecycle events to Relay for webhook delivery. Each lifecycle hook emits a typed event via relay.Relay.Send.

func New

func New(r *relay.Relay, opts ...Option) *Extension

New creates an Extension that emits Dispatch lifecycle events through the provided Relay instance.

func (*Extension) Name

func (h *Extension) Name() string

Name implements ext.Extension.

func (*Extension) OnCronFired

func (h *Extension) OnCronFired(ctx context.Context, entryName string, jobID id.JobID) error

OnCronFired implements ext.CronFired.

func (*Extension) OnJobCancelled

func (h *Extension) OnJobCancelled(ctx context.Context, j *job.Job) error

OnJobCancelled implements ext.JobCancelled.

func (*Extension) OnJobCompleted

func (h *Extension) OnJobCompleted(ctx context.Context, j *job.Job, elapsed time.Duration) error

OnJobCompleted implements ext.JobCompleted.

func (*Extension) OnJobDLQ

func (h *Extension) OnJobDLQ(ctx context.Context, j *job.Job, jobErr error) error

OnJobDLQ implements ext.JobDLQ.

func (*Extension) OnJobEnqueued

func (h *Extension) OnJobEnqueued(ctx context.Context, j *job.Job) error

OnJobEnqueued implements ext.JobEnqueued.

func (*Extension) OnJobFailed

func (h *Extension) OnJobFailed(ctx context.Context, j *job.Job, jobErr error) error

OnJobFailed implements ext.JobFailed.

func (*Extension) OnJobRetrying

func (h *Extension) OnJobRetrying(ctx context.Context, j *job.Job, attempt int, nextRunAt time.Time) error

OnJobRetrying implements ext.JobRetrying.

func (*Extension) OnJobStarted

func (h *Extension) OnJobStarted(ctx context.Context, j *job.Job) error

OnJobStarted implements ext.JobStarted.

func (*Extension) OnOperatorAction

func (h *Extension) OnOperatorAction(ctx context.Context, a ext.Action) error

OnOperatorAction implements ext.OperatorActionObserver. Operator events are system-level, like cron events, so they carry no tenant. A kind this version does not know becomes "dispatch.operator." plus the kind with its dots turned into underscores; it has no catalog entry, so Relay refuses it and the registry logs the error.

func (*Extension) OnWorkflowCompleted

func (h *Extension) OnWorkflowCompleted(ctx context.Context, r *workflow.Run, elapsed time.Duration) error

OnWorkflowCompleted implements ext.WorkflowCompleted.

func (*Extension) OnWorkflowFailed

func (h *Extension) OnWorkflowFailed(ctx context.Context, r *workflow.Run, runErr error) error

OnWorkflowFailed implements ext.WorkflowFailed.

func (*Extension) OnWorkflowStarted

func (h *Extension) OnWorkflowStarted(ctx context.Context, r *workflow.Run) error

OnWorkflowStarted implements ext.WorkflowStarted.

func (*Extension) OnWorkflowStepCompleted

func (h *Extension) OnWorkflowStepCompleted(ctx context.Context, r *workflow.Run, stepName string, elapsed time.Duration) error

OnWorkflowStepCompleted implements ext.WorkflowStepCompleted.

func (*Extension) OnWorkflowStepFailed

func (h *Extension) OnWorkflowStepFailed(ctx context.Context, r *workflow.Run, stepName string, stepErr error) error

OnWorkflowStepFailed implements ext.WorkflowStepFailed.

type Option

type Option func(*Extension)

Option configures a Extension.

func WithEvents

func WithEvents(events ...string) Option

WithEvents restricts the extension to emit only the listed event types. By default every event type in AllDefinitions is enabled. Unknown types are silently ignored.

func WithPayloadFunc

func WithPayloadFunc(eventType string, fn PayloadFunc) Option

WithPayloadFunc registers a custom payload builder for the given event type. The function replaces the default JSON payload for that event.

type PayloadFunc

type PayloadFunc func(args any) (any, error)

PayloadFunc builds a custom event payload for a specific event type. The args parameter contains the raw lifecycle arguments (job, error, duration, etc.) and the returned value becomes event.Event.Data.

Jump to

Keyboard shortcuts

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