Documentation
¶
Overview ¶
Package activity provides the call-site helpers that activity code uses inside a Hanzo Tasks worker. Zero upstream go.temporal.io dependencies.
Activities run inside a worker. The worker's task-dispatch loop builds an activity Scope per task, embeds it in the activity's context via NewContext, then calls the user's activity function. Inside the activity, GetInfo, GetLogger and RecordHeartbeat read that scope.
The contract is one-sided: the worker imports this package, not the other way round. Workers are free to plug [Scope.HeartbeatSink] into whatever transport they use (the reference worker uses luxfi/zap on port 9652).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLogger ¶
GetLogger returns a structured logger scoped to the activity. If ctx carries no scope, or the scope has no logger, log.Noop is returned so the caller never has to nil-check.
func NewContext ¶
NewContext returns a child context carrying scope. The returned context is what the worker should hand to the user's activity function. If scope is nil, ctx is returned unchanged.
func RecordHeartbeat ¶
RecordHeartbeat pings the worker that the activity is still running and attaches the given details. If ctx carries no scope, the call is a no-op. Details are defensively copied before being handed to the sink.
Types ¶
type Info ¶
type Info struct {
TaskToken []byte
WorkflowExecution WorkflowExecution
ActivityID string
ActivityType string
TaskQueue string
Attempt int32
ScheduledTime time.Time
StartedTime time.Time
}
Info contains information about a currently executing activity.
Values are a snapshot at the moment GetInfo was called. Mutating the returned value cannot affect the worker's state.
func FromContext ¶
FromContext returns the Info embedded in ctx and true, or a zero value and false if ctx carries no activity scope. Intended for worker-side code that needs to inspect the activity context without going through the logging/heartbeat helpers.
type Scope ¶
type Scope struct {
// Info is the per-task information exposed via [GetInfo].
Info Info
// Logger is returned by [GetLogger]. If nil, [GetLogger] returns
// [log.Noop]. The worker should pre-bind activity fields
// (activity_id, attempt, workflow_id) before assigning.
Logger log.Logger
// HeartbeatSink, if non-nil, is invoked by [RecordHeartbeat] after the
// scope records the details locally. The worker wires this to the
// transport that ships heartbeats to the task server. In tests this
// is typically left nil and the collected details are read via
// [Scope.Heartbeats].
HeartbeatSink func(details ...interface{})
// contains filtered or unexported fields
}
Scope is the worker-owned execution context for a single activity task. The worker constructs one, calls NewContext to embed it in the activity context, then invokes the user's activity function. The helpers in this package read the scope back out of the context.
A Scope is safe for concurrent use: activity code may call RecordHeartbeat from goroutines it spawns.
func (*Scope) Heartbeats ¶
func (s *Scope) Heartbeats() [][]interface{}
Heartbeats returns a copy of every details set recorded on this scope, in the order they were recorded. Intended for tests; the returned slice is independent of the scope's internal storage and safe to modify.
type WorkflowExecution ¶
WorkflowExecution identifies a workflow run.