contextutil

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetadataKeyWorkflowType is the context metadata key for workflow type.
	// These keys are serialized into a protobuf message (ContextMetadata) and sent
	// in the "contextmetadata-bin" gRPC trailer. The "-bin" suffix causes gRPC to
	// base64-encode the value on the wire, so metadata values may contain arbitrary
	// bytes including HTTP/2-unsafe control characters.
	MetadataKeyWorkflowType = "workflow-type"
	// MetadataKeyWorkflowTaskQueue is the context metadata key for workflow task queue
	MetadataKeyWorkflowTaskQueue = "workflow-task-queue"
	// MetadataKeyStandaloneActivityType is the context metadata key for standalone activity type.
	MetadataKeyStandaloneActivityType = "standalone-activity-type"
	// MetadataKeyStandaloneActivityTaskQueue is the context metadata key for standalone activity task queue.
	MetadataKeyStandaloneActivityTaskQueue = "standalone-activity-task-queue"
)

Variables

This section is empty.

Functions

func ActivityTaskQueueKey

func ActivityTaskQueueKey(scheduledEventID int64) string

ActivityTaskQueueKey returns the metadata key for an activity's task queue, keyed by scheduled event ID.

func ActivityTypeKey

func ActivityTypeKey(scheduledEventID int64) string

ActivityTypeKey returns the metadata key for an activity's type, keyed by scheduled event ID.

func ContextHasMetadata added in v1.31.0

func ContextHasMetadata(ctx context.Context) bool

ContextHasMetadata returns true if the context has metadata support. This can be used to debug whether a context has been properly initialized with metadata.

func ContextMetadataGet added in v1.31.0

func ContextMetadataGet(ctx context.Context, key string) (any, bool)

ContextMetadataGet retrieves a metadata value from the context.

func ContextMetadataGetActivityTypeAndTaskQueue

func ContextMetadataGetActivityTypeAndTaskQueue(ctx context.Context) (activityType string, taskQueue string, ok bool)

ContextMetadataGetActivityTypeAndTaskQueue scans the context metadata for a single activity's type and task queue. Returns false if no activity metadata is found or if multiple activities are present.

func ContextMetadataGetAll added in v1.31.0

func ContextMetadataGetAll(ctx context.Context) map[string]any

ContextMetadataGetAll retrieves all metadata from the context as a map copy.

func ContextMetadataGetMarkedActivityIDs

func ContextMetadataGetMarkedActivityIDs(ctx context.Context) []string

ContextMetadataGetMarkedActivityIDs returns the marked activity IDs from the context.

func ContextMetadataMarkActivityID

func ContextMetadataMarkActivityID(ctx context.Context, activityID string) bool

ContextMetadataMarkActivityID marks an activity ID on the context for metadata resolution. The handler knows which activity (from the task token) but not its type or task queue. Mutable state knows the activity details but not which activity the request targets. This bridges the two: the handler marks the ID, and SetContextMetadata (during closeTransaction) resolves it to type and task queue from mutable state. Cannot be used for transactions that remove the activity from mutable state (e.g., activity completion), since it won't be available for resolution.

func ContextMetadataSet added in v1.31.0

func ContextMetadataSet(ctx context.Context, key string, value any) bool

ContextMetadataSet sets a metadata key-value pair in the context, overwriting any existing value.

func WithDeadlineBuffer

func WithDeadlineBuffer(
	parent context.Context,
	timeout time.Duration,
	buffer time.Duration,
) (context.Context, context.CancelFunc)

WithDeadlineBuffer returns a child context with a deadline that ensures that at least buffer amount of time remains after the child deadline expires and before the parent deadline expires. The returned context timeout is therefore <= the requested timeout. If the parent deadline itself does not allow buffer amount of time, then the returned context deadline expires immediately. Use this method to create child context when the child cannot use all of parent's deadline but instead there is a need to leave some time for parent to do some post-work.

func WithMetadataContext added in v1.31.0

func WithMetadataContext(ctx context.Context) context.Context

WithMetadataContext adds a metadata context to the given context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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