busruntime

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DeliveryMetadataVersion = 1

DeliveryMetadataVersion identifies the direct-delivery metadata understood by this version of the runtime and driver integration contract.

Variables

This section is empty.

Functions

func DeferUntilDeliveryCommitted added in v0.3.0

func DeferUntilDeliveryCommitted(ctx context.Context, fn func()) bool

DeferUntilDeliveryCommitted registers fn when ctx carries a driver-owned settlement boundary. It returns false when the driver cannot report settlement, allowing callers to preserve legacy immediate behavior.

func DeliveryExecutionContext added in v0.3.0

func DeliveryExecutionContext(ctx context.Context) context.Context

DeliveryExecutionContext detaches only marked accepted deliveries, preserving ordinary caller cancellation semantics.

func IsPermanent added in v0.3.0

func IsPermanent(err error) bool

IsPermanent reports whether an error requests terminal application settlement.

func IsUncommitted added in v0.3.0

func IsUncommitted(err error) bool

IsUncommitted reports whether an application outcome still needs to be committed.

func MarkDeliveryApplicationStateCommitted added in v0.3.0

func MarkDeliveryApplicationStateCommitted(ctx context.Context) bool

MarkDeliveryApplicationStateCommitted records that the current generation durably mutated application state before physical delivery settlement. SQL drivers use this only to preserve truthful provenance across a later same-attempt infrastructure redelivery.

func Permanent added in v0.3.0

func Permanent(err error) error

Permanent marks an application error as terminal regardless of remaining retries.

func PreserveDeliveryContext added in v0.3.0

func PreserveDeliveryContext(source context.Context, replacement context.Context) context.Context

PreserveDeliveryContext carries runtime-owned delivery state from source into a replacement context while retaining replacement cancellation, deadlines, and user values. Source runtime values override replacement values, and the same permit pointers are reused so handler return still expires permission.

func Uncommitted added in v0.3.0

func Uncommitted(err error) error

Uncommitted marks an infrastructure error for redelivery without consuming application retries.

func WithDeliveryAttempt added in v0.3.0

func WithDeliveryAttempt(ctx context.Context, attempt DeliveryAttempt) context.Context

WithDeliveryAttempt attaches physical delivery metadata for orchestration and middleware classification.

func WithDeliveryMetadata added in v0.3.0

func WithDeliveryMetadata(ctx context.Context, metadata DeliveryMetadata) context.Context

WithDeliveryMetadata attaches direct-job correlation to one physical handler invocation without exposing transport framing to the application payload.

func WithDeliveryProvenance added in v0.3.0

func WithDeliveryProvenance(ctx context.Context, provenance DeliveryProvenance) context.Context

WithDeliveryProvenance attaches settlement-owner generation identity to one physical handler invocation. Callers must not manufacture recovery evidence for an ordinary duplicate.

func WithIndependentExecution added in v0.3.0

func WithIndependentExecution(ctx context.Context) context.Context

WithIndependentExecution retains cancellation for admission while marking accepted local execution as independent.

Types

type AttemptDecision added in v0.3.0

type AttemptDecision uint8

AttemptDecision describes how a worker must settle an application attempt.

const (
	// AttemptSucceeded commits successful handler execution.
	AttemptSucceeded AttemptDecision = iota
	// AttemptRetry schedules a later application attempt after the current attempt failed.
	AttemptRetry
	// AttemptFailed commits a permanent or exhausted application failure.
	AttemptFailed
	// AttemptRedeliver retries infrastructure work without consuming the application retry budget.
	AttemptRedeliver
)

func ClassifyAttempt added in v0.3.0

func ClassifyAttempt(attempt DeliveryAttempt, err error) AttemptDecision

ClassifyAttempt maps a handler result to the settlement decision owned by its worker or driver.

type Continuation added in v0.3.0

type Continuation struct {
	ID          string
	WorkflowID  string
	DispatchID  string
	Phase       string
	Sequence    int
	Declaration int
	Trigger     ContinuationSummary
}

Continuation identifies one durable hook invocation across physical retries.

type ContinuationOutcome added in v0.3.0

type ContinuationOutcome struct {
	Invocation      Continuation
	Status          string
	FailureCategory string
	CreatedAt       time.Time
	ScheduledAt     time.Time
	SettledAt       time.Time
}

ContinuationOutcome is the durable scheduling and settlement view of one triggered hook.

type ContinuationScope added in v0.3.0

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

ContinuationScope owns short-lived permission for one runtime's handlers to enqueue descendants while that runtime drains. Its zero value grants no permission; use NewContinuationScope.

func NewContinuationScope added in v0.3.0

func NewContinuationScope() *ContinuationScope

NewContinuationScope creates an unforgeable runtime-specific continuation scope.

func (*ContinuationScope) Owns added in v0.3.0

func (s *ContinuationScope) Owns(ctx context.Context) bool

Owns reports whether ctx carries a still-active permit issued by this scope.

func (*ContinuationScope) Permit added in v0.3.0

func (s *ContinuationScope) Permit(ctx context.Context) (context.Context, func())

Permit marks ctx only until the returned release function runs. Runtime adapters release the permit as the originating handler returns so escaped contexts cannot enqueue during a later drain.

type ContinuationSummary added in v0.3.0

type ContinuationSummary struct {
	Kind      string
	MemberID  string
	Total     int
	Pending   int
	Processed int
	Failed    int
	NextIndex int
	Completed bool
	Cancelled bool
}

ContinuationSummary contains safe immutable trigger counters without application payloads.

type DeliveryAttempt added in v0.3.0

type DeliveryAttempt struct {
	Number   int
	MaxRetry int
}

DeliveryAttempt identifies one application attempt and its configured retry budget. Number is zero-based, and MaxRetry is the number of retries after the initial attempt.

func DeliveryAttemptFromContext added in v0.3.0

func DeliveryAttemptFromContext(ctx context.Context) (DeliveryAttempt, bool)

DeliveryAttemptFromContext returns physical delivery metadata when a worker supplied it.

func (DeliveryAttempt) Exhausted added in v0.3.0

func (a DeliveryAttempt) Exhausted() bool

Exhausted reports whether the current application attempt has consumed its retry budget.

type DeliveryMetadata added in v0.3.0

type DeliveryMetadata struct {
	Continuation  *Continuation `json:"continuation,omitempty"`
	SchemaVersion int           `json:"schema_version"`
	DispatchID    string        `json:"dispatch_id,omitempty"`
	JobID         string        `json:"job_id,omitempty"`
	ChainID       string        `json:"chain_id,omitempty"`
	BatchID       string        `json:"batch_id,omitempty"`
	Queue         string        `json:"queue,omitempty"`
}

DeliveryMetadata carries correlation for an ordinary direct job without changing its application type or payload. Its JSON representation is the canonical persisted and transported driver metadata record.

func CloneDeliveryMetadata added in v0.3.0

func CloneDeliveryMetadata(metadata DeliveryMetadata) DeliveryMetadata

CloneDeliveryMetadata isolates invocation pointers when correlation crosses value and context boundaries.

func DeliveryMetadataFromContext added in v0.3.0

func DeliveryMetadataFromContext(ctx context.Context) (DeliveryMetadata, bool)

DeliveryMetadataFromContext returns supported direct-job correlation supplied by a compatible worker runtime. Missing and unknown versions are untrusted.

type DeliveryProvenance added in v0.3.0

type DeliveryProvenance struct {
	// GenerationID is an opaque identifier generated by the settlement owner
	// for the physical delivery currently invoking the handler.
	GenerationID string
	// RecoveredGenerationID identifies the earlier unsettled generation when
	// that identity survived reclamation.
	RecoveredGenerationID string
	// Recovered reports stale-generation evidence even when a legacy delivery
	// did not retain an owner identifier.
	Recovered bool
}

DeliveryProvenance identifies the current settlement generation and any earlier generation whose durable delivery definitely remained unsettled. Workflow state must independently prove which generation owns a transition.

func DeliveryProvenanceFromContext added in v0.3.0

func DeliveryProvenanceFromContext(ctx context.Context) (DeliveryProvenance, bool)

DeliveryProvenanceFromContext returns settlement-owner generation identity without treating it as proof of a workflow transition.

type DeliverySettlement added in v0.3.0

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

DeliverySettlement defers facts that become true only after a worker commits broker settlement. Its zero value is ready for use, and Commit is idempotent.

func WithDeliverySettlement added in v0.3.0

func WithDeliverySettlement(ctx context.Context) (context.Context, *DeliverySettlement)

WithDeliverySettlement attaches one settlement boundary to a handler context. Drivers that acknowledge or delete deliveries after handler execution use the returned value to commit deferred facts.

func (*DeliverySettlement) ApplicationStateCommitted added in v0.3.0

func (s *DeliverySettlement) ApplicationStateCommitted() bool

ApplicationStateCommitted reports whether the current generation durably mutated application state before the driver attempted physical settlement.

func (*DeliverySettlement) Commit added in v0.3.0

func (s *DeliverySettlement) Commit()

Commit publishes every deferred fact after the driver has positively settled the delivery.

type DeliverySettlementIdentity added in v0.3.0

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

DeliverySettlementIdentity is an opaque, comparable identity for one physical handler invocation. It permits correlation without exposing the driver's authority to commit the underlying settlement.

func DeliverySettlementIdentityFromContext added in v0.3.0

func DeliverySettlementIdentityFromContext(ctx context.Context) (DeliverySettlementIdentity, bool)

DeliverySettlementIdentityFromContext returns the opaque identity for the physical settlement boundary attached to ctx.

type DirectRuntime added in v0.3.0

type DirectRuntime interface {
	Runtime
	// BusDispatchDirect submits application bytes with correlation kept in the metadata channel.
	BusDispatchDirect(ctx context.Context, jobType string, payload []byte, metadata DeliveryMetadata, opts JobOptions) error
}

DirectRuntime extends Runtime with canonical direct-job dispatch. Its embedded Runtime registration method handles both application types and retained legacy envelopes.

type Handler

type Handler func(ctx context.Context, job InboundJob) error

Handler processes one inbound delivery for the orchestration runtime.

type InboundJob

type InboundJob interface {
	Bind(dst any) error
	PayloadBytes() []byte
}

InboundJob is the minimal job view the orchestration runtime needs from the queue layer.

type JobOptions

type JobOptions struct {
	Queue     string
	Delay     time.Duration
	Timeout   time.Duration
	Retry     int
	Backoff   time.Duration
	UniqueFor time.Duration
}

JobOptions carries delivery policy from orchestration into the queue runtime.

type Runtime

type Runtime interface {
	BusRegister(jobType string, handler Handler)
	BusDispatch(ctx context.Context, jobType string, payload []byte, opts JobOptions) error
	StartWorkers(ctx context.Context) error
	Shutdown(ctx context.Context) error
}

Runtime is the queue runtime surface required by the orchestration engine.

Jump to

Keyboard shortcuts

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