callback

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(t models.CallbackType, h Handler)

Register associates a callback type with a handler.

Types

type Dispatcher

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

Dispatcher loads callbacks and invokes handlers.

func Default

func Default() *Dispatcher

Default returns the process-wide dispatcher using the shared DB connection.

func NewDispatcher

func NewDispatcher(conn *gorm.DB) *Dispatcher

NewDispatcher constructs a Dispatcher backed by the provided DB.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(ctx context.Context, jobID, runID uuid.UUID, runErr error) error

Dispatch loads callbacks for the job and executes them sequentially.

func (*Dispatcher) RetryFailed

func (d *Dispatcher) RetryFailed(ctx context.Context, runID uuid.UUID) error

RetryFailed retries callbacks for the supplied run that most recently failed.

func (*Dispatcher) WithHTTPClient

func (d *Dispatcher) WithHTTPClient(client *http.Client)

WithHTTPClient overrides the HTTP client used by handlers (primarily for tests).

type Handler

type Handler interface {
	Handle(ctx context.Context, cfg json.RawMessage, meta Metadata) error
}

Handler executes a callback with the provided configuration and metadata.

type Metadata

type Metadata struct {
	JobID       uuid.UUID         `json:"job_id"`
	JobAlias    string            `json:"job_alias"`
	RunID       uuid.UUID         `json:"run_id"`
	Params      map[string]string `json:"params,omitempty"`
	Status      string            `json:"status"`
	Error       string            `json:"error,omitempty"`
	StartedAt   time.Time         `json:"started_at"`
	CompletedAt *time.Time        `json:"completed_at,omitempty"`
	Tasks       []TaskState       `json:"tasks"`
}

Metadata captures the job/run context sent to callbacks.

type NotificationConfig

type NotificationConfig struct {
	URL       string            `json:"url"`
	Webhook   string            `json:"webhook_url"`
	Headers   map[string]string `json:"headers,omitempty"`
	UserAgent string            `json:"user_agent,omitempty"`
}

NotificationConfig describes the webhook target.

type NotificationHandler

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

NotificationHandler posts run metadata to a webhook endpoint.

func NewNotificationHandler

func NewNotificationHandler(client *http.Client) *NotificationHandler

NewNotificationHandler constructs a notification handler with the provided client.

func (*NotificationHandler) Handle

func (h *NotificationHandler) Handle(ctx context.Context, cfgRaw json.RawMessage, meta Metadata) error

Handle sends a POST request containing the run metadata.

type TaskState

type TaskState struct {
	TaskID      uuid.UUID         `json:"task_id"`
	AtomID      uuid.UUID         `json:"atom_id"`
	Engine      models.AtomEngine `json:"engine"`
	Image       string            `json:"image"`
	Command     []string          `json:"command"`
	RuntimeID   string            `json:"runtime_id,omitempty"`
	Status      string            `json:"status"`
	Result      string            `json:"result,omitempty"`
	Error       string            `json:"error,omitempty"`
	StartedAt   *time.Time        `json:"started_at,omitempty"`
	CompletedAt *time.Time        `json:"completed_at,omitempty"`
}

TaskState summarises an individual task run.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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