Documentation
¶
Overview ¶
Package selvedge binds typed activities and durable workflows to Selvedge. Producer and Worker own their private handles and lifecycle; New(app) retains the caller-owned native path. Selvedge owns persistence, dispatch and codecs.
Index ¶
- Variables
- func Declare[I, O any](r Role, wf execution.Workflow[I, O]) error
- func Register[I, O any](activities *Activities, activity execution.Activity[I, O], ...) error
- func RegisterWorkflow[I, O any](w *Worker, wf execution.Workflow[I, O], ...) error
- type Activities
- type Admission
- type AdmissionConflictError
- type AdmissionUncertainError
- type Job
- type Producer
- type ProducerOption
- type Role
- type Worker
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotRunning means the role cannot admit operations in its current state. ErrNotRunning = errors.New("selvedge: workflow role is not running") // ErrRegistrationSealed means the role has left its initial registration state. ErrRegistrationSealed = errors.New("selvedge: workflow registration is sealed") // ErrShutdownIncomplete means this caller stopped waiting; cleanup continues. ErrShutdownIncomplete = errors.New("selvedge: workflow shutdown wait interrupted") // ErrInputEncoding rejects input before insertion, including unstable or invalid UTF-8 JSON. ErrInputEncoding = errors.New("selvedge: invalid workflow input encoding") )
Functions ¶
func Declare ¶
Declare records the workflow's name and exact input/output types before Start. Repeating the same contract is idempotent; name/type collisions are errors.
func Register ¶
func Register[I, O any](activities *Activities, activity execution.Activity[I, O], handler func(context.Context, I) (O, error), options sv.ActivityOptions) error
Register installs a typed activity with native Selvedge options and codecs. Its generic signature preserves the input and output types for Selvedge; Activities therefore does not implement execution.ActivityRegistrar.
func RegisterWorkflow ¶
func RegisterWorkflow[I, O any](w *Worker, wf execution.Workflow[I, O], fn func(*sv.WorkflowContext, I) (O, error)) error
RegisterWorkflow declares and installs one worker-owned native workflow.
Types ¶
type Activities ¶
type Activities struct {
// contains filtered or unexported fields
}
Activities registers named handlers on one Selvedge app. A Worker-owned registry shares its registration gate; New(app) retains caller ownership.
func New ¶
func New(app *sv.App) (*Activities, error)
New binds activity registration to app without starting or stopping it.
func (*Activities) Scope ¶
func (a *Activities) Scope(ctx *sv.WorkflowContext) execution.ActivityExecutor
Scope binds execution to ctx, including its cancellation and detached-scope behavior. The context.Context arguments of execution calls do not replace this native workflow context. Futures retain the scope that scheduled them.
type Admission ¶
type Admission struct {
// ID is the caller-chosen durable instance identifier.
ID string
// Created reports that this call inserted the job, rather than reconciled it.
Created bool
}
Admission identifies an existing or newly inserted durable job.
type AdmissionConflictError ¶
type AdmissionConflictError struct {
// ID is the occupied instance ID.
ID string
// Workflow is the requested workflow name.
Workflow string
// ExistingWorkflow is the persisted workflow name.
ExistingWorkflow string
// InputDiffers reports unequal frozen encoded input bytes.
InputDiffers bool
// ChildInstance reports persisted parent identity rather than a root job.
ChildInstance bool
// ExistingInput is a copy of stored bytes for prior-attempt reconciliation.
ExistingInput []byte
}
AdmissionConflictError reports an existing job with a different identity. ExistingInput can match a prior uncertain attempt; conflict alone does not prove that the caller's logical request was never admitted.
type AdmissionUncertainError ¶
type AdmissionUncertainError struct {
// ID is the caller-chosen instance ID to reuse on retry.
ID string
// Input is a copy of this call's frozen bytes, not a fresh encoding.
Input []byte
// Err is the native admission or reconciliation-read failure.
Err error
}
AdmissionUncertainError means this call may have committed Input under ID. Retain Input across retries; a later rejected call does not prove absence.
type Job ¶
type Job[O any] struct { // ID identifies the durable instance. ID string // State is the native Running, Completed, Failed or Cancelled status. State sv.WorkflowStatus // Output is the decoded completed result; other states leave its zero value. Output O // Err is the recorded failure for Failed or Cancelled, not a lookup error. Err error // StartedAt records native admission time. StartedAt time.Time // UpdatedAt records the identity snapshot's last native update time. UpdatedAt time.Time }
Job is a typed snapshot. Output is meaningful only in the Completed state.
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
Producer owns a producer-only native handle. Declare contracts before Start. Its zero value is unusable; construct it with NewProducer.
func NewProducer ¶
func NewProducer(opts ...ProducerOption) (*Producer, error)
NewProducer configures an owned producer without opening storage until Start.
type ProducerOption ¶
ProducerOption configures native producer storage, migration and notifications. Native worker options are ignored; client observability wraps operations.
type Role ¶
type Role interface {
// contains filtered or unexported methods
}
Role is a producer or worker with a private native handle and one lifecycle.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker owns a native worker and its workflow and activity registrations. Its zero value is unusable; construct it with NewWorker.
func (*Worker) Activities ¶
func (w *Worker) Activities() *Activities
Activities returns the registry sharing this worker's registration lifecycle.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
durable/contract
Package contract contains the application-owned metadata job shared by binaries.
|
Package contract contains the application-owned metadata job shared by binaries. |
|
durable/producer
command
Command producer submits or inspects an object-metadata job without running it.
|
Command producer submits or inspects an object-metadata job without running it. |
|
durable/worker
command
Command worker executes the application's object-metadata jobs.
|
Command worker executes the application's object-metadata jobs. |