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
- func AllDefinitions() []catalog.WebhookDefinition
- func RegisterAll(ctx context.Context, r *relay.Relay) error
- type Extension
- func (h *Extension) Name() string
- func (h *Extension) OnCronFired(ctx context.Context, entryName string, jobID id.JobID) error
- func (h *Extension) OnJobCancelled(ctx context.Context, j *job.Job) error
- func (h *Extension) OnJobCompleted(ctx context.Context, j *job.Job, elapsed time.Duration) error
- func (h *Extension) OnJobDLQ(ctx context.Context, j *job.Job, jobErr error) error
- func (h *Extension) OnJobEnqueued(ctx context.Context, j *job.Job) error
- func (h *Extension) OnJobFailed(ctx context.Context, j *job.Job, jobErr error) error
- func (h *Extension) OnJobRetrying(ctx context.Context, j *job.Job, attempt int, nextRunAt time.Time) error
- func (h *Extension) OnJobStarted(ctx context.Context, j *job.Job) error
- func (h *Extension) OnOperatorAction(ctx context.Context, a ext.Action) error
- func (h *Extension) OnWorkflowCompleted(ctx context.Context, r *workflow.Run, elapsed time.Duration) error
- func (h *Extension) OnWorkflowFailed(ctx context.Context, r *workflow.Run, runErr error) error
- func (h *Extension) OnWorkflowStarted(ctx context.Context, r *workflow.Run) error
- func (h *Extension) OnWorkflowStepCompleted(ctx context.Context, r *workflow.Run, stepName string, elapsed time.Duration) error
- func (h *Extension) OnWorkflowStepFailed(ctx context.Context, r *workflow.Run, stepName string, stepErr error) error
- type Option
- type PayloadFunc
Constants ¶
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.
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.
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 ¶
New creates an Extension that emits Dispatch lifecycle events through the provided Relay instance.
func (*Extension) OnCronFired ¶
OnCronFired implements ext.CronFired.
func (*Extension) OnJobCancelled ¶
OnJobCancelled implements ext.JobCancelled.
func (*Extension) OnJobCompleted ¶
OnJobCompleted implements ext.JobCompleted.
func (*Extension) OnJobEnqueued ¶
OnJobEnqueued implements ext.JobEnqueued.
func (*Extension) OnJobFailed ¶
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 ¶
OnJobStarted implements ext.JobStarted.
func (*Extension) OnOperatorAction ¶
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 ¶
OnWorkflowFailed implements ext.WorkflowFailed.
func (*Extension) OnWorkflowStarted ¶
OnWorkflowStarted implements ext.WorkflowStarted.
type Option ¶
type Option func(*Extension)
Option configures a Extension.
func WithEvents ¶
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 ¶
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.