codec

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

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

func New

func New(opts ...Option) (*Codec, error)

New instantiates a Codec. WithURL is a required option.

An error may be returned if incompatible options are configured or if a connection to the remote payload storage service cannot be established.

func (*Codec) Decode

func (c *Codec) Decode(payloads []*common.Payload) ([]*common.Payload, error)

func (*Codec) Encode

func (c *Codec) Encode(payloads []*common.Payload) ([]*common.Payload, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithCustomHeader

func WithCustomHeader(header string, value string) Option

WithCustomHeader adds a custom header to append to the http headers of the request sent to LargePayloadService when called with the same header it will not override the header but instead will append to its value. fails when passed an empty header.

func WithDecodeOnly

func WithDecodeOnly() Option

WithDecodeOnly set whether to skip the Url health check during initialisation.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom http.Client.

If unspecified, http.DefaultClient will be used.

func WithHTTPRoundTripper

func WithHTTPRoundTripper(rt http.RoundTripper) Option

WithHTTPRoundTripper sets custom Transport on the http.Client.

This may be used to implement use cases including authentication or tracing.

func WithMinBytes

func WithMinBytes(bytes uint32) Option

WithMinBytes configures the minimum size of an event payload needed to trigger encoding using the large payload codec. Any payload smaller than this value will be transparently persisted in workflow history.

The default value is 128000, or 128KB.

Setting this too low can lead to degraded performance, since decoding requires an additional network round trip per payload. This can add up quickly when replaying a workflow with a large number of events.

According to https://docs.temporal.io/workflows, the hard limit for workflow history size is 50k events and 50MB. A workflow with exactly 50k events can therefore in theory have an average event payload size of 1048 bytes.

In practice this worst case is very unlikely, since common workflow event types such as WorkflowTaskScheduled or WorkflowTaskCompleted do not include user defined payloads. If we estimate that one quarter of events have payloads just below the cutoff, then we can calculate how many events total would fit in one workflow's history (the point before which we must call ContinueAsNew):

AverageNonUserTaskBytes = 1024 (generous estimate for events like WorkflowTaskScheduled)
CodecMinBytes = 128_000
AverageEventBytes = (AverageNonUserTaskBytes * 3 + CodecMinBytes) / 4 = 32_768
MaxHistoryEventBytes = 50_000_000
MaxHistoryEventCount = MaxHistoryEventBytes / AverageEventBytes = 1525

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace sets the Temporal namespace the client using this codec is connected to. This option is mandatory.

func WithURL

func WithURL(u string) Option

WithURL sets the endpoint for the remote payload storage service. This option is mandatory.

func WithVersion

func WithVersion(version string) Option

WithVersion sets the version of the LPS API to use.

func WithoutUrlHealthCheck

func WithoutUrlHealthCheck() Option

WithoutUrlHealthCheck when set will skip the Url health check during initialisation.

Jump to

Keyboard shortcuts

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