restatecontext

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BufPool sync.Pool
View Source
var CancelledFailureValue = func() statemachine.Value {
	failure := pbinternal.Failure{}
	failure.SetCode(409)
	failure.SetMessage("Cancelled")
	return statemachine.ValueFailure{Failure: &failure}
}()

Functions

func ExecuteInvocation

func ExecuteInvocation(ctx context.Context, logger *slog.Logger, stateMachine *statemachine.StateMachine, conn io.ReadWriteCloser, handler Handler, dropReplayLogs bool, logHandler slog.Handler, attemptHeaders map[string][]string) error

Types

type AfterFuture

type AfterFuture interface {
	// Done blocks waiting on the remaining duration of the sleep.
	// It is *not* safe to call this in a goroutine - use Context.Select if you want to wait on multiple
	// results at once. Can return a terminal error in the case where the invocation was cancelled mid-sleep,
	// hence Done() should always be called, even afterFuture using Context.Select.
	Done() error
	Selectable
}

After is a coreHandle on a Sleep operation which allows you to do other work concurrently with the sleep.

type AttachFuture

type AttachFuture interface {
	Selectable
	Response(output any) error
}

type AwakeableFuture

type AwakeableFuture interface {
	Selectable
	Id() string
	Result(output any) error
}

type Client

type Client interface {
	RequestFuture(input any, opts ...options.RequestOption) ResponseFuture
	Request(input any, output any, opts ...options.RequestOption) error
	Send(input any, opts ...options.SendOption) Invocation
}

type Context

type Context interface {
	context.Context
	Log() *slog.Logger
	Request() *Request

	// available outside of .Run()
	Rand() rand.Rand
	Sleep(d time.Duration, opts ...options.SleepOption) error
	After(d time.Duration, opts ...options.SleepOption) AfterFuture
	Service(service, method string, options ...options.ClientOption) Client
	Object(service, key, method string, options ...options.ClientOption) Client
	Workflow(seservice, workflowID, method string, options ...options.ClientOption) Client
	CancelInvocation(invocationId string)
	AttachInvocation(invocationId string, opts ...options.AttachOption) AttachFuture
	Awakeable(options ...options.AwakeableOption) AwakeableFuture
	ResolveAwakeable(id string, value any, options ...options.ResolveAwakeableOption)
	RejectAwakeable(id string, reason error)
	Select(futs ...Selectable) Selector
	WaitIter(futs ...Selectable) WaitIterator
	Run(fn func(ctx RunContext) (any, error), output any, options ...options.RunOption) error
	RunAsync(fn func(ctx RunContext) (any, error), options ...options.RunOption) RunAsyncFuture

	// available on all keyed handlers
	Get(key string, output any, options ...options.GetOption) (bool, error)
	Keys() ([]string, error)
	Key() string

	// available on non-shared keyed handlers
	Set(key string, value any, options ...options.SetOption)
	Clear(key string)
	ClearAll()

	// available on workflow handlers
	Promise(name string, options ...options.PromiseOption) DurablePromise
}

type DurablePromise

type DurablePromise interface {
	Selectable
	Result(output any) (err error)
	Peek(output any) (ok bool, err error)
	Resolve(value any) error
	Reject(reason error) error
}

type Handler

type Handler interface {
	GetOptions() *options.HandlerOptions
	InputPayload() *encoding.InputPayload
	OutputPayload() *encoding.OutputPayload
	HandlerType() *internal.ServiceHandlerType
	Call(ctx Context, request []byte) (output []byte, err error)
}

Handler is implemented by all Restate handlers

type Invocation

type Invocation interface {
	GetInvocationId() string
}

type Request

type Request struct {
	// The unique id that identifies the current function invocation. This id is guaranteed to be
	// unique across invocations, but constant across reties and suspensions.
	ID string
	// Request headers - the following headers capture the original invocation headers, as provided to
	// the ingress.
	Headers map[string]string
	// Attempt headers - the following headers are sent by the restate runtime.
	// These headers are attempt specific, generated by the restate runtime uniquely for each attempt.
	// These headers might contain information such as the W3C trace context, and attempt specific information.
	AttemptHeaders map[string][]string
	// Raw unparsed request body
	Body []byte
}

type ResponseFuture

type ResponseFuture interface {
	Selectable
	Invocation
	Response(output any) error
}

type RunAsyncFuture added in v0.17.0

type RunAsyncFuture interface {
	Selectable
	Result(output any) error
}

type RunContext

type RunContext interface {
	context.Context

	// Log obtains a coreHandle on a slog.Logger which already has some useful fields (invocationID and method)
	// By default, this logger will not output messages if the invocation is currently replaying
	// The log handler can be set with `.WithLogger()` on the server object
	Log() *slog.Logger

	// Request gives extra information about the request that started this invocation
	Request() *Request
}

RunContext is passed to [Run] closures and provides the limited set of Restate operations that are safe to use there.

type Selectable

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

type Selector

type Selector interface {
	// Remaining returns whether there are still operations that haven't been returned by Select().
	// There will always be exactly the same number of results as there were operations
	// given to Context.Select
	Remaining() bool
	// Select blocks on the next completed operation or returns nil if there are none left
	Select() Selectable
}

Selector is an iterator over a list of blocking Restate operations that are running in the background.

type WaitIterator added in v0.21.0

type WaitIterator interface {
	// Next returns whether there are still operations that haven't been returned by Value().
	// If returns false, no more operations will be completed. After returning false, Err() should be checked.
	Next() bool

	// Err returns an error if the waiter was canceled using Restate's cancellation feature.
	Err() error

	// Value returns the current value of this iterator, or nil if the iterator returned Next previously.
	// Panics if called before the first Next
	Value() Selectable
}

WaitIterator lets you

Jump to

Keyboard shortcuts

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