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

scriptevents

package
v1.152.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package scriptevents enqueues a run of each automation that names a webhook source for every event the source stores (#2332). The webhook receiver (posted events and form submissions) and the imap poller hand it a source's events once they are durable; each event becomes one run with trigger event, carrying the event as run.event, executed by the run queue's workers under the script's saved author roles, as a scheduled run is.

Nothing runs inline: the sender was answered when the event was stored, and enqueuing is one transaction per script that names the source. A failure to enqueue is logged, and never fails the delivery, which stored the event whatever happens to its runs.

Index

Constants

View Source
const (
	KeyID         = "id"
	KeyType       = "type"
	KeyKey        = "key"
	KeyReceivedAt = "received_at"
	KeySource     = "source"
	KeyPayload    = "payload"
)

The keys run.event carries.

View Source
const DefaultMaxQueued = 100

DefaultMaxQueued is how many pending event runs a script may hold when scripts.events.max_queued names none; an event past it is recorded as skipped_backlog.

Variables

This section is empty.

Functions

func Value

func Value(source string, ev whevent.Event) map[string]any

Value is ev as run.event reads it: its id, type, key, when it was received and from which source, and its payload decoded. A payload that is not JSON, which a source never stores, is handed over as its text.

Types

type Enqueuer

type Enqueuer struct {
	Store   Store
	Scripts Scripts
	// MaxQueued bounds each script's pending event runs; zero is
	// DefaultMaxQueued.
	MaxQueued int
	// Timeout bounds one source's enqueue; zero is ten seconds.
	Timeout time.Duration
}

Enqueuer enqueues the runs of a source's events.

func (*Enqueuer) Stored

func (e *Enqueuer) Stored(ctx context.Context, source string, events []whevent.Event)

Stored enqueues one run of each script that names source for each of events, which the source has made durable. It does not return an error: the events are stored, and what failed is logged.

type EventEnqueue

type EventEnqueue struct {
	Enqueued int
	Skipped  int
	Already  int
}

EventEnqueue is what enqueuing one source's events for one script did (#2332): runs made pending, events recorded as skipped past the bound, and events that already had a run, which made none.

type EventSummary

type EventSummary struct {
	Pending       int        `json:"pending"`
	SkippedSince  int        `json:"skipped_since"`
	LastEventRun  *time.Time `json:"last_event_run,omitempty"`
	LastSkippedAt *time.Time `json:"last_skipped_at,omitempty"`
}

EventSummary is how a script's event runs stand: how many wait, and how many were skipped past the bound since a moment.

type PostgresStore

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

PostgresStore keeps event runs in script_runs and reads which scripts run for a source from scripts (#2332).

func NewStore

func NewStore(db *sql.DB) *PostgresStore

NewStore is the PostgreSQL event run store.

func (*PostgresStore) EnqueueEvents

func (s *PostgresStore) EnqueueEvents(ctx context.Context, runs []*script.Run, maxQueued int) (EventEnqueue, error)

EnqueueEvents writes one run per event for the script the runs name, in one transaction holding the script's row: each is pending while the script's pending event runs are under maxQueued, and recorded as skipped_backlog past it. An event that already has a run makes none. A worker is woken when any run was made pending. Every run carries the same script and version; its Event, EventSource and EventID name the event.

func (*PostgresStore) EventSummary

func (s *PostgresStore) EventSummary(ctx context.Context, scriptID string, since time.Time) (EventSummary, error)

EventSummary reports how the script's event runs stand, counting the ones skipped since since.

func (*PostgresStore) ScriptsForSource

func (s *PostgresStore) ScriptsForSource(ctx context.Context, source string) ([]string, error)

ScriptsForSource returns the ids of the scripts that run for source.

type Scripts

type Scripts interface {
	GetByID(ctx context.Context, id string) (*script.Script, error)
	GetVersion(ctx context.Context, scriptID string, version int) (*script.Version, error)
}

Scripts reads a script and the version a run of it executes (scriptstore.Store).

type Store

type Store interface {
	ScriptsForSource(ctx context.Context, source string) ([]string, error)
	EnqueueEvents(ctx context.Context, runs []*script.Run, maxQueued int) (EventEnqueue, error)
}

Store lists the scripts that run for a source and enqueues their runs (PostgresStore).

Directories

Path Synopsis
Package sourcerule is who may run a managed script for which webhook source (#2332).
Package sourcerule is who may run a managed script for which webhook source (#2332).

Jump to

Keyboard shortcuts

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