dispatchproto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

Variables

This section is empty.

Functions

func CoroutineState

func CoroutineState(state Any) interface {
	PollOption
	PollResultOption
	ResponseOption
}

CoroutineState sets the coroutine state.

func CorrelationID

func CorrelationID(correlationID uint64) interface {
	CallOption
	CallResultOption
}

CorrelationID sets the correlation ID on a function call or result.

func DispatchID

func DispatchID(id ID) interface {
	CallResultOption
	RequestOption
}

DispatchID sets the opaque identifier for the function call.

func Input

func Input(input Any) interface {
	CallOption
	RequestOption
}

Input sets the output from a function call or Response.

func Output

func Output(output Any) interface {
	CallResultOption
	ExitOption
	ResponseOption
}

Output sets the output from a function call or Response.

Types

type Any

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

Any represents any value.

func Bool

func Bool(v bool) Any

Bool creates an Any that contains a boolean value.

func Bytes

func Bytes(v []byte) Any

Bytes creates an Any that contains a bytes value.

func Duration

func Duration(v time.Duration) Any

Duration creates an Any that contains a duration value.

func Float

func Float(v float64) Any

Float creates an Any that contains a floating point value.

func Int

func Int(v int64) Any

Int creates an Any that contains an integer value.

func Marshal

func Marshal(v any) (Any, error)

Marshal packages a Go value into an Any, for use as input to or output from a Dispatch function.

Primitive values (booleans, integers, floats, strings, bytes, timestamps, durations) are supported, along with values that implement either proto.Message, json.Marshaler, encoding.TextMarshaler or encoding.BinaryMarshaler. Slices and maps are also supported, as long as they are JSON-like in shape.

func Nil

func Nil() Any

Nil creates an Any that contains nil/null.

func String

func String(v string) Any

String creates an Any that contains a string value.

func Time

func Time(v time.Time) Any

Time creates an Any that contains a time value.

func Uint

func Uint(v uint64) Any

Uint creates an Any that contains an unsigned integer value.

func (Any) Equal

func (a Any) Equal(other Any) bool

Equal is true if this Any is equal to another.

func (Any) String

func (a Any) String() string

String is the string representation of the any value.

func (Any) TypeURL

func (a Any) TypeURL() string

TypeURL is a URL that uniquely identifies the type of the serialized value.

func (Any) Unmarshal

func (a Any) Unmarshal(v any) error

Unmarshal unmarshals the value.

type Call

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

Call is a function call.

func NewCall

func NewCall(endpoint, function string, opts ...CallOption) Call

NewCall creates a Call.

func (Call) Clone

func (c Call) Clone() Call

Clone creates a copy of the call.

func (Call) CorrelationID

func (c Call) CorrelationID() uint64

CorrelationID is an opaque value that gets repeated in CallResult to correlate asynchronous calls with their results.

func (Call) Endpoint

func (c Call) Endpoint() string

Endpoint is the URL of the service where the function resides.

func (Call) Equal

func (c Call) Equal(other Call) bool

Equal is true if the call is equal to another.

func (Call) Expiration

func (c Call) Expiration() time.Duration

Expiration is the maximum time the function is allowed to run.

func (Call) Function

func (c Call) Function() string

Function is the name of the function to call.

func (Call) Input

func (c Call) Input() Any

Input is input to the function.

func (Call) Request

func (c Call) Request() Request

Request converts the call to a request.

func (Call) String

func (c Call) String() string

String is the string representation of the call.

func (Call) Version

func (c Call) Version() string

Version of the application to select during execution. The version is an optional field and not supported by all platforms.

func (Call) With

func (c Call) With(opts ...CallOption) Call

With creates a copy of the Call with additional options applied.

type CallOption

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

CallOption configures a Call.

func Expiration

func Expiration(expiration time.Duration) CallOption

Expiration sets a function call expiration.

func Version

func Version(version string) CallOption

Version sets a function call version.

type CallResult

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

CallResult is a function call result.

func NewCallResult

func NewCallResult(opts ...CallResultOption) CallResult

NewCallResult creates a CallResult.

func (CallResult) Clone

func (r CallResult) Clone() CallResult

Clone creates a copy of the call.

func (CallResult) CorrelationID

func (r CallResult) CorrelationID() uint64

CorrelationID is the value that was originally passed in the Call message.

This field is intended to be used by the function to correlate the result with the original call.

func (CallResult) DispatchID

func (r CallResult) DispatchID() ID

DispatchID is the opaque identifier for the function call.

func (CallResult) Equal

func (r CallResult) Equal(other CallResult) bool

Equal is true if the call result is equal to another.

func (CallResult) Error

func (r CallResult) Error() (Error, bool)

Error is the error that occurred during execution of the function.

It is valid to have both an output and an error, in which case the output might contain a partial result.

func (CallResult) Output

func (r CallResult) Output() (Any, bool)

Output is output from the function.

func (CallResult) String

func (r CallResult) String() string

String is the string representation of the function call result.

func (CallResult) With

func (r CallResult) With(opts ...CallResultOption) CallResult

With creates a copy of the CallResult with additional options applied.

type CallResultOption

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

CallResultOption configures a CallResult.

type Error

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

Error is an error that occurred during execution of a function.

func Errorf

func Errorf(msg string, args ...any) Error

Errorf creates an Error from the specified message and args.

func NewError

func NewError(err error) Error

NewError creates an Error from a Go error.

func NewErrorMessage

func NewErrorMessage(typ, message string, opts ...ErrorOption) Error

NewErrorMessage creates an Error.

func (Error) Equal

func (e Error) Equal(other Error) bool

Equal is true if the error is equal to another.

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

func (Error) Message

func (e Error) Message() string

Message is a human-readable message providing more details about the error.

func (Error) String

func (e Error) String() string

String is the string representation of the call.

func (Error) Traceback

func (e Error) Traceback() []byte

Traceback is the encoded stack trace for the error.

The format is language-specific, encoded in the standard format used by each programming language to represent stack traces. Not all languages have stack traces for errors, so in some cases the value might be omitted.

func (Error) Type

func (e Error) Type() string

Type is the type of error that occurred.

This value is language and application specific. It is is used to provide debugging information to the user.

func (Error) Value

func (e Error) Value() []byte

Value is the language-specific representation of the error.

This is used to enable propagation of the error value between instances of a program, by encoding information allowing the error value to be reconstructed.

type ErrorOption

type ErrorOption func(*Error)

ErrorOption configures an Error.

func ErrorValue

func ErrorValue(value []byte) ErrorOption

ErrorValue sets the language-specific representation of the error.

func Traceback

func Traceback(traceback []byte) ErrorOption

Traceback sets the encoded stack trace for the error.

type Exit

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

Exit is a directive that terminates a function call.

func NewExit

func NewExit(opts ...ExitOption) Exit

NewExit creates an Exit directive.

func (Exit) Equal

func (e Exit) Equal(other Exit) bool

Equal is true if an Exit directive is equal to another.

func (Exit) Error

func (e Exit) Error() (Error, bool)

Error is the error from the function call result the exit directive carries.

func (Exit) Output

func (e Exit) Output() (Any, bool)

Output is the output from the function call result the exit directive carries.

func (Exit) Result

func (e Exit) Result() (CallResult, bool)

Result is the function call result the exit directive carries.

func (Exit) String

func (e Exit) String() string

String is the string representation of the Exit directive.

func (Exit) TailCall

func (e Exit) TailCall() (Call, bool)

TailCall is the tail call the exit directive carries.

type ExitOption

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

ExitOption configures an Exit directive.

func TailCall

func TailCall(tailCall Call) ExitOption

TailCall sets the tail call.

type Function

type Function func(context.Context, Request) Response

Function is a Dispatch function.

type FunctionMap

type FunctionMap map[string]Function

FunctionMap is a map of Dispatch functions.

func (FunctionMap) Run

func (m FunctionMap) Run(ctx context.Context, req Request) Response

Run runs a function.

type ID

type ID string

ID is an identifier for a dispatched function call.

type Poll

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

Poll is a general purpose directive used to spawn function calls and wait for their results, and/or to implement sleep/timer functionality.

func NewPoll

func NewPoll(minResults, maxResults int, maxWait time.Duration, opts ...PollOption) Poll

NewPoll creates a Poll directive.

func (Poll) Calls

func (p Poll) Calls() []Call

Calls are the function calls attached to the poll directive.

func (Poll) CoroutineState

func (p Poll) CoroutineState() Any

CoroutineState is a snapshot of the function's state.

It's passed back in the PollResult when the function is resumed.

func (Poll) Equal

func (p Poll) Equal(other Poll) bool

Equal is true if the poll directive is equal to another.

func (Poll) MaxResults

func (p Poll) MaxResults() int32

MaxResults is the maximum number of call results to deliver in the PollResult.

func (Poll) MaxWait

func (p Poll) MaxWait() time.Duration

MaxWait is the maximum amount of time the function should be suspended for while waiting for call results.

func (Poll) MinResults

func (p Poll) MinResults() int32

MinResults is the minimum number of call results to wait for before the function is resumed.

The function will be suspended until either MinResults are available, or the MaxWait timeout is reached, whichever comes first.

func (Poll) Result

func (p Poll) Result() PollResult

Result creates a result for the Poll directive, that carries the same coroutine state.

func (Poll) String

func (p Poll) String() string

String is the string representation of the poll directive.

type PollOption

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

PollOption configures a Poll directive.

func Calls

func Calls(calls ...Call) PollOption

Calls adds calls to a Poll directive.

type PollResult

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

PollResult is the result of a poll operation.

func NewPollResult

func NewPollResult(opts ...PollResultOption) PollResult

NewPollResult creates a PollResult

func (PollResult) Clone

func (r PollResult) Clone() PollResult

Clone creates a copy of the result.

func (PollResult) CoroutineState

func (r PollResult) CoroutineState() Any

CoroutineState is the state recorded when the function was suspended while polling.

func (PollResult) Equal

func (r PollResult) Equal(other PollResult) bool

Equal is true if the poll result is equal to another.

func (PollResult) Error

func (r PollResult) Error() (Error, bool)

Error is an error that occured while processing a Poll directive.

An error indicates that none of the calls were dispatched, and must be resubmitted after the error cause has been resolved.

func (PollResult) Results

func (r PollResult) Results() []CallResult

Results are the function call results attached to the poll result.

func (PollResult) String

func (r PollResult) String() string

String is the string representation of the poll result.

func (PollResult) With

func (r PollResult) With(opts ...PollResultOption) PollResult

With creates a copy of the PollResult with additional options applied.

type PollResultOption

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

PollResultOption configures a PollResult.

func CallResults

func CallResults(results ...CallResult) PollResultOption

CallResults sets the call results for the poll operation.

type Request

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

Request is a request from Dispatch to run a function.

The Request carries a "directive", to either start execution with input (Input), or to resume execution with the results of a previous Response directive (e.g. PollResult).

func NewRequest

func NewRequest(function string, opts ...RequestOption) Request

NewRequest creates a Request.

func (Request) Clone

func (r Request) Clone() Request

Clone creates a copy of the request.

func (Request) CreationTime

func (r Request) CreationTime() (time.Time, bool)

CreationTime is the creation time of the function call.

func (Request) DispatchID

func (r Request) DispatchID() ID

DispatchID is the opaque identifier for the function call.

func (Request) Equal

func (r Request) Equal(other Request) bool

Equal is true if the request is equal to another.

func (Request) ExpirationTime

func (r Request) ExpirationTime() (time.Time, bool)

ExpirationTime is the expiration time of the function call.

func (Request) Function

func (r Request) Function() string

Function is the identifier of the function to run.

func (Request) Input

func (r Request) Input() (Any, bool)

Input is input to the function, along with a boolean flag that indicates whether the request carries a directive to start the function with the input.

func (Request) ParentID

func (r Request) ParentID() ID

ParentID is the opaque identifier for the parent function call.

Functions can call other functions via Poll. If this function call has a parent function call, the identifier of the parent can be found here. If the function call does not have a parent, the field will be empty.

func (Request) PollResult

func (r Request) PollResult() (PollResult, bool)

PollResult is the poll result, along with a boolean flag that indicates whether the request carries a directive to resume a function with poll results.

func (Request) RootID

func (r Request) RootID() ID

RootID is the opaque identifier for the root function call.

When functions call other functions, an additional level on the call hierarchy tree is created. This field carries the identifier of the root function call in the tree.

func (Request) String

func (r Request) String() string

String is the string representation of the request.

func (Request) With

func (r Request) With(opts ...RequestOption) Request

With creates a copy of the Request with additional options applied.

type RequestOption

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

RequestOption configures a Request.

func CreationTime

func CreationTime(timestamp time.Time) RequestOption

CreationTime sets the creation time for the function call.

func ExpirationTime

func ExpirationTime(timestamp time.Time) RequestOption

ExpirationTime sets the expiration time for the function call.

func ParentDispatchID

func ParentDispatchID(id ID) RequestOption

ParentDispatchID sets the opaque identifier of the parent function call.

func RootDispatchID

func RootDispatchID(id ID) RequestOption

ParentDispatchID sets the opaque identifier of the root function call.

type Response

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

Response is a response to Dispatch after a function has run.

The Response carries a "directive" to either terminate execution (Exit), or to suspend the function while waiting and/or performing operations on the Dispatch side (e.g. Poll).

func NewResponse

func NewResponse(opts ...ResponseOption) Response

NewResponse creates a Response.

func NewResponseError

func NewResponseError(err error) Response

NewResponseError creates a Response from the specified error.

func NewResponseErrorf

func NewResponseErrorf(msg string, args ...any) Response

NewResponseErrorf creates a Response from the specified error message and args.

func (Response) Clone

func (r Response) Clone() Response

Clone creates a copy of the response.

func (Response) Equal

func (r Response) Equal(other Response) bool

Equal is true if the response is equal to another.

func (Response) Error

func (r Response) Error() (Error, bool)

Error is the error from the exit directive attached to the response.

func (Response) Exit

func (r Response) Exit() (Exit, bool)

Exit is the exit directive on the response.

func (Response) Marshal

func (r Response) Marshal() ([]byte, error)

Marshal marshals the response.

func (Response) OK

func (r Response) OK() bool

OK is true if the response carries an OKStatus status.

func (Response) Output

func (r Response) Output() (Any, bool)

Output is the output from an exit directive attached to the response.

func (Response) Poll

func (r Response) Poll() (Poll, bool)

Poll is the poll directive on the response.

func (Response) Result

func (r Response) Result() (CallResult, bool)

Result is the result from the exit directive on the response.

func (Response) Status

func (r Response) Status() Status

Status is the response status.

func (Response) String

func (r Response) String() string

String is the string representation of the response.

func (Response) With

func (r Response) With(opts ...ResponseOption) Response

With creates a copy of the Response with additional options applied.

type ResponseOption

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

ResponseOption configures a Response.

type Status

type Status int

Status categorizes the success or failure conditions resulting from an execution request.

func ErrorStatus

func ErrorStatus(err error) Status

ErrorStatus categorizes an error to return a Status code.

func StatusOf

func StatusOf(v any) Status

StatusOf returns the Status associated with an object.

The object can provide a status by implementing interface{ Status() Status }.

func (Status) GoString

func (s Status) GoString() string

func (Status) String

func (s Status) String() string

type StatusError

type StatusError Status

StatusError is a Status as an error.

func (StatusError) Error

func (e StatusError) Error() string

func (StatusError) Status

func (e StatusError) Status() Status

Jump to

Keyboard shortcuts

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