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

hooks

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package hooks schedules finite, detached checkout synchronization workers.

Index

Constants

This section is empty.

Variables

View Source
var ErrCooldown = errors.New("service startup cooling down")
View Source
var ErrUnavailable = errors.New("collection source unavailable")
View Source
var ErrUnchanged = errors.New("checkout unchanged")

Functions

func Directory added in v0.2.1

func Directory(stateDir string) string

Directory is the versioned hook state under diffx's private state root.

func LaunchDetached

func LaunchDetached(executable, directory, job string) error

LaunchDetached closes every inherited stream so hook hosts can finish as soon as Schedule returns. The worker reports errors to its bounded private log.

Types

type Activity

type Activity struct {
	Time          time.Time `json:"time"`
	Stage         string    `json:"stage,omitempty"`
	Status        string    `json:"status,omitempty"`
	Job           string    `json:"job,omitempty"`
	InputPath     string    `json:"inputPath,omitempty"`
	Path          string    `json:"path,omitempty"`
	Agent         string    `json:"agent,omitempty"`
	RunID         string    `json:"runId,omitempty"`
	Branch        string    `json:"branch,omitempty"`
	BranchID      string    `json:"branchId,omitempty"`
	RepositoryKey string    `json:"repositoryKey,omitempty"`
	CheckoutKey   string    `json:"checkoutKey,omitempty"`
	Base          string    `json:"base,omitempty"`
	Head          string    `json:"head,omitempty"`
	Destination   string    `json:"destination,omitempty"`
	SubmissionID  string    `json:"submissionId,omitempty"`
	DiagnosticID  string    `json:"diagnosticId,omitempty"`
	ContextID     string    `json:"contextId,omitempty"`
	Attempt       int       `json:"attempt,omitempty"`
	FileCount     int       `json:"fileCount,omitempty"`
	Reason        string    `json:"reason,omitempty"`
	Error         string    `json:"error,omitempty"`
}

Activity contains collection and delivery metadata, never captured contents.

type Engine

type Engine struct {
	Directory        string
	Expand           func(context.Context, Event) ([]Event, error)
	ValidateLocation func(Event, Event) error
	Normalize        func(context.Context, Event) (Event, error)
	Resolve          func(context.Context, Event) (Target, error)
	Collect          func(context.Context, Event, string) (ingestion.Request, string, error)
	Deliver          func(context.Context, Target, ingestion.Request) (string, error)
	// Confirm checks cached context freshness only after collection reports
	// unchanged. Production callers provide it to detect other producers.
	Confirm func(context.Context, Target, string) (bool, error)
	// SuppressInitialEmpty proves a clean capture has no retained stream history.
	// Errors keep the conservative publication path.
	SuppressInitialEmpty func(context.Context, Target, ingestion.Request) (bool, error)
	Launch               func(string) error
	Timeout              time.Duration
}

func (Engine) Log

func (engine Engine) Log(err error)

Log never writes into the agent's conversation or inherits its output pipes.

func (Engine) Record

func (engine Engine) Record(activity Activity)

Record persists a bounded JSONL activity entry. Logging failures never affect collection. The short blocking lock preserves concurrent lifecycle events.

func (Engine) RecordJob

func (engine Engine) RecordJob(job string, event Event, activity Activity)

RecordJob also atomically replaces the job's readable latest status. Callers supply stage/status and can override event metadata (e.g. its original path).

func (Engine) Retry

func (engine Engine) Retry(event Event) error

Retry is bounded, event-driven, and restricted to the invoking environment's route and config. Credentials are inherited, never read from persisted jobs.

func (Engine) Run

func (engine Engine) Run(ctx context.Context, job string) error

Run owns one checkout until all observed requests are processed. Queue writes and worker exit share a short lock, preventing a trigger losing its worker.

func (Engine) Schedule

func (engine Engine) Schedule(event Event) error

Schedule writes only a small request. Collection and transport never run here.

func (Engine) Start

func (engine Engine) Start(ctx context.Context, destination string, start func(context.Context) error) error

Start serializes startup attempts across checkouts and suppresses repeated failures. Call after a health probe fails; callback should probe again before starting, since another worker may have started the service while waiting.

func (Engine) Statuses

func (engine Engine) Statuses() ([]Activity, error)

type Event

type Event struct {
	Path            string `json:"path"`
	InputPath       string `json:"inputPath,omitempty"`
	Identity        string `json:"identity,omitempty"`
	Branch          string `json:"branch,omitempty"`
	Base            string `json:"base,omitempty"`
	Resolved        bool   `json:"resolved,omitempty"`
	Retry           bool   `json:"-"`
	Agent           string `json:"agent"`
	RunID           string `json:"runId,omitempty"`
	SessionName     string `json:"sessionName,omitempty"`
	ConfigFile      string `json:"configFile,omitempty"`
	Routing         string `json:"routing,omitempty"`
	RecoveryRouting string `json:"recoveryRouting,omitempty"`
}

type Target

type Target = submission.Target

Identity identifies the server's persistent database (or memory instance). An unknown identity disables suppression and prevents uncertain replay.

Jump to

Keyboard shortcuts

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