publicwebhook

package
v2.22.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package publicwebhook gives per-DAG webhooks public URLs through the Dagu Cloud relay: it holds the relay connection, keeps the relay's set of URLs in step with the webhooks, and starts a run for each delivery it accepts.

Index

Constants

View Source
const (
	OutcomeStarted  = "started"
	OutcomeWaiting  = "waiting"
	OutcomeRejected = "rejected"
	OutcomeSkipped  = "skipped"
	OutcomeIgnored  = "ignored"
	OutcomeFailed   = "failed"
)

What became of a delivery, as its log shows it. A waiting delivery is back at the relay, which sends it again; a rejected one failed its sender's signature check; a skipped one is about an event that starts no run.

View Source
const LogSize = 20

LogSize is how many deliveries a webhook's log keeps.

Variables

View Source
var ErrInvalidRun = errors.New("the run cannot start")

ErrInvalidRun marks a run the DAG or the delivery cannot start.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Credentials returns the server's Dagu Cloud credentials, and false
	// while it is not connected.
	Credentials func() (license.CloudCredentials, bool)
	Webhooks    Webhooks
	Store       Store
	Runs        Runs
	// HTTPClient reaches Dagu Cloud; nil means a client with a 30-second
	// timeout.
	HTTPClient *http.Client
	Hello      cloudrelay.Hello
	// MaxPayloadSize bounds a body that starts a run, as for local webhook
	// requests; zero leaves it to the relay.
	MaxPayloadSize int
}

Config is what the service works with.

type Delivery

type Delivery struct {
	ID       string    `json:"id"`
	Received time.Time `json:"received"`
	Size     int       `json:"size"`
	// Event names what the request is about, as its sender labels it.
	Event   string `json:"event,omitempty"`
	Outcome string `json:"outcome"`
	// RunID names the run a started delivery started.
	RunID string `json:"runId,omitempty"`
	// Error says why a delivery was rejected, skipped, or failed.
	Error string `json:"error,omitempty"`
}

Delivery is one request the relay handed over for a webhook, as its log keeps it. The body is not kept; a started delivery's body is in its run.

type Log

type Log struct {
	Deliveries []Delivery `json:"deliveries,omitempty"`
	Missed     Missed     `json:"missed"`
}

Log is a webhook's latest deliveries, newest first, and its missed counts.

type Missed

type Missed struct {
	Expired int       `json:"expired"`
	Refused int       `json:"refused"`
	Since   time.Time `json:"since,omitzero"`
}

Missed counts the deliveries the relay dropped for a webhook since an admin last dismissed them: those that waited past 7 days, and those it refused while 1,000 waited.

type Runs

type Runs interface {
	// DAG loads the DAG a webhook starts.
	DAG(ctx context.Context, dagName string) (*ir.DAG, error)
	// Queued counts the runs waiting on the DAG's queue.
	Queued(ctx context.Context, dag *ir.DAG) (int, error)
	// Enqueue queues a run of the DAG named runID with params. A run by that
	// ID that already exists counts as queued. An error wrapping
	// ErrInvalidRun means waiting cannot make the run start.
	Enqueue(ctx context.Context, dagName string, dag *ir.DAG, runID, params string) error
}

Runs starts the runs deliveries ask for.

type Service

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

Service holds the relay connection for the server's public webhook URLs.

func New

func New(cfg Config) *Service

New creates a Service.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run holds the relay connection while the server is connected to Dagu Cloud and some webhook has a public URL, or the relay still holds URLs since turned off, until ctx is done.

type Status

type Status struct {
	// Connected is set while the connection is open.
	Connected bool `json:"connected"`
	// URL is what this server's public webhook URLs start with, once the
	// relay has said.
	URL string `json:"url,omitempty"`
	// MaxHooks is the most public URLs the plan allows, from the latest
	// ticket.
	MaxHooks int `json:"maxHooks,omitempty"`
	// LeftOut names the DAGs whose public URLs exceed MaxHooks and are not
	// held at the relay.
	LeftOut []string `json:"leftOut,omitempty"`
	// Holding is set while the relay holds URLs this server sent, so a URL
	// turned off while the server was away is dropped when it returns.
	Holding bool `json:"holding,omitempty"`
	// Error says why the server is not connected.
	Error     string    `json:"error,omitempty"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Status is the relay connection as the scheduler that holds it last saw it.

type Store

type Store interface {
	// Log returns a webhook's log; an empty one when it has none.
	Log(ctx context.Context, webhookID string) (Log, error)
	// AddDelivery puts d first in a webhook's log, replacing an entry for the
	// same delivery, and keeps the latest LogSize.
	AddDelivery(ctx context.Context, webhookID string, d Delivery) error
	// AddMissed adds to a webhook's missed counts.
	AddMissed(ctx context.Context, webhookID string, expired, refused int, at time.Time) error
	// ClearMissed dismisses a webhook's missed counts.
	ClearMissed(ctx context.Context, webhookID string) error
	// DeleteLog removes a webhook's log, as when its public URL is turned off.
	DeleteLog(ctx context.Context, webhookID string) error
	// Status returns the relay's status; the zero Status before any.
	Status(ctx context.Context) (Status, error)
	// SetStatus replaces the relay's status.
	SetStatus(ctx context.Context, status Status) error
}

Store keeps the relay's status and each public webhook's log. Several processes share it: the scheduler writes deliveries and status, and the server reads them and dismisses missed counts.

type Webhooks

type Webhooks interface {
	// ListComplete returns every webhook, or an error when any cannot be
	// read.
	ListComplete(ctx context.Context) ([]*auth.Webhook, error)
	GetByID(ctx context.Context, id string) (*auth.Webhook, error)
}

Webhooks reads the webhooks that may have public URLs.

Jump to

Keyboard shortcuts

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