Documentation
¶
Overview ¶
Package env is what every node of one service shares: the manifest being declared into and the wiring of events, hooks and activities to a transport. Declaration packages reach it through the node a Scope wraps, so nothing is process-global.
Index ¶
- Constants
- Variables
- func CallKeyOf(ctx context.Context) string
- func WithActivityInfo(ctx context.Context, info ActivityInfo) context.Context
- func WithCallKey(ctx context.Context, key string) context.Context
- func WithIncoming(ctx context.Context, in Incoming) context.Context
- type ActivityInfo
- type Broker
- type Caller
- type Delivery
- type Env
- func (e *Env) Activities() map[string]Handler
- func (e *Env) Activity(name string, h Handler)
- func (e *Env) ActivityHandler(name string) (Handler, bool)
- func (e *Env) Bound(hook string) bool
- func (e *Env) BoundChanges(ctx context.Context) <-chan struct{}
- func (e *Env) Broker() Broker
- func (e *Env) Caller() Caller
- func (e *Env) HookTimeout() time.Duration
- func (e *Env) OwnActivities() map[string]Handler
- func (e *Env) OwnActivity(name string, h Handler)
- func (e *Env) Reactor(r Reactor)
- func (e *Env) ReactorOf(consumer string) (Reactor, bool)
- func (e *Env) Reactors() []Reactor
- func (e *Env) RegisterWorker(fn func(registry any))
- func (e *Env) SetBound(hooks []string)
- func (e *Env) SetBroker(b Broker)
- func (e *Env) SetCaller(c Caller)
- func (e *Env) SetHookTimeout(d time.Duration)
- func (e *Env) SetWorkflowClient(fn func() (any, error))
- func (e *Env) WorkerRegistrations() []func(registry any)
- func (e *Env) WorkflowClient() (any, error)
- type Handler
- type Incoming
- type Message
- type NonRetryableError
- type Reactor
- type RetryAfterError
Constants ¶
const DefaultHookTimeout = 30 * time.Second
DefaultHookTimeout bounds a hook call nothing else bounds: no deadline on the context, none on the call or the declaration, no configured one.
Variables ¶
var ErrNoBinding = errors.New("no binding")
ErrNoBinding: backplane has no binding for the hook.
ErrUnavailable: no transport carries this call (yet).
Functions ¶
func WithActivityInfo ¶
func WithActivityInfo(ctx context.Context, info ActivityInfo) context.Context
WithActivityInfo attaches info to a handler's ctx.
func WithCallKey ¶
WithCallKey marks the hook call made with ctx as idempotent under key: the transport runs one call per key. Empty key: an ordinary call.
Types ¶
type ActivityInfo ¶
type ActivityInfo struct {
Attempt int32 // 1 for the first
Binding string // binding or rule that called, from the envelope
Step string // its step
Key string // "<workflow id>/<activity id>": the same for every attempt
Deadline time.Time // of this attempt; zero when unbounded
Heartbeat func(details ...any)
}
ActivityInfo is what the transport knows about the activity execution a handler serves.
func ActivityInfoOf ¶
func ActivityInfoOf(ctx context.Context) (ActivityInfo, bool)
ActivityInfoOf is the info attached by WithActivityInfo.
type Caller ¶
Caller carries hook calls (Temporal Nexus; a stub in tests). Payloads are encoded JSON.
type Delivery ¶
type Delivery struct {
MaxDeliver int // deliveries before the dead letter
Concurrency int // handlers in flight at once
Timeout time.Duration // of one handler call
Redelivery backoff.Policy // delay after a failed delivery
StartAll bool // a new consumer starts at the stream's first message
// Ordered: one message in flight across every instance (strict order).
Ordered bool
// InactiveThreshold: the server deletes the consumer after this long
// without an instance pulling; zero never.
InactiveThreshold time.Duration
}
Delivery is how a reactor's messages are delivered, as its author declared it; a zero field means the transport's default.
type Env ¶
type Env struct {
Service string
Manifest *manifest.Builder
// contains filtered or unexported fields
}
Env of one service.
func (*Env) Activities ¶
Activities lists the declared activities by name.
func (*Env) Activity ¶
Activity stores the handler of a declared activity. A name an own activity has panics: both are one Temporal activity name on the queue.
func (*Env) ActivityHandler ¶
ActivityHandler returns the handler of a declared activity.
func (*Env) Bound ¶ added in v0.6.8
Bound reports whether hook (its short name) may have a binding: false only when backplane's set is known and lacks it.
func (*Env) BoundChanges ¶ added in v0.6.8
BoundChanges signals after every change of the bound set until ctx ends; one pending signal at most.
func (*Env) HookTimeout ¶
HookTimeout is the platform default deadline of a hook call: the configured one or DefaultHookTimeout. Never zero.
func (*Env) OwnActivities ¶ added in v0.6.32
OwnActivities lists the activities of OwnActivity by name.
func (*Env) OwnActivity ¶ added in v0.6.32
OwnActivity stores the handler of an activity only the service's own workflows run: registered on the worker as a declared one is, not in the manifest and not callable by the platform. A name taken panics.
func (*Env) RegisterWorker ¶
RegisterWorker adds fn, called with the service's Temporal worker (worker.Registry) whenever the worker is built.
func (*Env) SetBound ¶ added in v0.6.8
SetBound installs the service's hooks with a binding in force (names without the service prefix) and signals BoundChanges when it differs; nil returns to unknown.
func (*Env) SetHookTimeout ¶
SetHookTimeout sets the platform default deadline of a hook call; 0 or less restores DefaultHookTimeout.
func (*Env) SetWorkflowClient ¶
SetWorkflowClient installs how the Temporal client is reached.
func (*Env) WorkerRegistrations ¶
WorkerRegistrations are the functions given to RegisterWorker.
func (*Env) WorkflowClient ¶
WorkflowClient is the connected Temporal client (a client.Client).
type Incoming ¶
type Incoming struct {
ID string
Source string
Type string
Subject string
Time time.Time
Attempt int
Consumer string
Extensions map[string]string
}
Incoming is the metadata of the event a reactor's handler is running for; the transport puts it on the handler's context.
type Message ¶
type Message struct {
Event string // full name "<service>.<Event>"
Key string // CloudEvents subject, optional
ID string // ce-id and the dedup id; empty: a new UUID
Time time.Time
Payload []byte // encoded JSON
// Extensions are CloudEvents extension attributes by name, without the
// ce- prefix; the event package validates the names.
Extensions map[string]string
}
Message is one event to publish.
type NonRetryableError ¶
type NonRetryableError struct{ Err error }
NonRetryableError marks a handler error the transport must not retry: the input is wrong, retrying cannot help.
func (NonRetryableError) Error ¶
func (e NonRetryableError) Error() string
func (NonRetryableError) Unwrap ¶
func (e NonRetryableError) Unwrap() error
type Reactor ¶
type Reactor struct {
Event string // full name "<service>.<Event>"
Consumer string // unique within the service
Handler Handler
Delivery Delivery
}
Reactor is a declared durable consumer of another service's event.
type RetryAfterError ¶ added in v0.6.0
RetryAfterError marks a handler error retryable no sooner than Delay.
func (RetryAfterError) Error ¶ added in v0.6.0
func (e RetryAfterError) Error() string
func (RetryAfterError) Unwrap ¶ added in v0.6.0
func (e RetryAfterError) Unwrap() error