Documentation
¶
Overview ¶
Package flow is the Go SDK for clevix-worker, a durable workflow engine on Cloudflare. Its API follows Inngest's inngestgo.
Make a client with NewClient, add functions with CreateFunction, and serve them with client.Serve(), which returns an http.Handler for your app's one endpoint (for example /api/flow). Steps are in the step package, parallel steps in the group package.
Index ¶
- Constants
- func BoolPtr(b bool) *bool
- func IntPtr(i int) *int
- func NoRetryError(err error) error
- func RetryAtError(err error, at time.Time) error
- func StrPtr(s string) *string
- type AppManifest
- type BatchEvents
- type CancelOn
- type Client
- func (c *Client) AppID() string
- func (c *Client) Manifest(serveURL string) AppManifest
- func (c *Client) Send(ctx context.Context, event Event) (string, error)
- func (c *Client) SendMany(ctx context.Context, events []Event) ([]string, error)
- func (c *Client) Serve() http.Handler
- func (c *Client) Sync(ctx context.Context, serveURL string) (int, []byte, error)
- type ClientOpts
- type Concurrency
- type Debounce
- type Event
- type FunctionConfig
- type FunctionOpts
- type GenericEvent
- type Handler
- type Input
- type InputCtx
- type MultipleTriggers
- type Priority
- type RateLimit
- type SDKInfo
- type ServableFunction
- type Singleton
- type StepError
- type Throttle
- type Timeouts
- type Trigger
- type Triggerable
Constants ¶
const Version = "0.1.0"
Version is this SDK's version, sent in the manifest.
Variables ¶
This section is empty.
Functions ¶
func NoRetryError ¶
NoRetryError wraps err so it is not retried. Returned from a step.Run callback, the step fails at once. Returned from the handler, the run fails at once.
func RetryAtError ¶
RetryAtError wraps err so the next attempt runs at the given time.
Types ¶
type AppManifest ¶
type AppManifest struct {
AppID string `json:"appId"`
URL string `json:"url"`
SDK *SDKInfo `json:"sdk,omitempty"`
Functions []FunctionConfig `json:"functions"`
}
AppManifest is what the app sends on sync and returns on GET.
type BatchEvents ¶
BatchEvents runs the function with up to MaxSize events, or after Timeout.
type CancelOn ¶
type CancelOn struct {
Event string
// Match is a field path in both events, for example "data.orderId".
Match *string
// If is an expression over event (the trigger) and async (the new event).
If *string
// Timeout stops listening after this long. Zero means as long as the run lives.
Timeout time.Duration
}
CancelOn cancels a run when a matching event arrives.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client holds an app's functions and talks to the engine.
func NewClient ¶
func NewClient(opts ClientOpts) (*Client, error)
NewClient makes a client. It fails if AppID or a signing key is not valid.
func (*Client) Manifest ¶
func (c *Client) Manifest(serveURL string) AppManifest
Manifest builds the app's manifest with serveURL as the app URL.
func (*Client) Serve ¶
Serve returns the http.Handler for the app's one endpoint:
- POST runs a function (signed by the engine).
- PUT syncs: sends the manifest to the engine and returns its answer. Call it on deploy, for example: curl -X PUT https://app/api/flow
- GET returns the manifest (signed GET with an empty body).
Without a signing key, and not in dev mode, it answers every request with 500 NoSigningKey.
type ClientOpts ¶
type ClientOpts struct {
// AppID names the app. Required.
AppID string
// SigningKey checks calls from the engine and signs sync. Env: FLOW_SIGNING_KEY.
SigningKey *string
// SigningKeyFallback is the old key while rotating. Env: FLOW_SIGNING_KEY_FALLBACK.
SigningKeyFallback *string
// EventKey is used to send events. Env: FLOW_EVENT_KEY.
EventKey *string
// BaseURL is the engine URL. Env: FLOW_BASE_URL.
BaseURL *string
// ServeURL is the public URL of this app's endpoint, sent in the manifest.
// Env: FLOW_SERVE_URL. If unset, it is taken from the incoming request.
ServeURL *string
// Dev turns off signature checks. Env: FLOW_DEV=1.
Dev *bool
// HTTPClient is used for sync and sending events. Default: http.DefaultClient.
HTTPClient *http.Client
}
ClientOpts configures a client. Fields left nil are read from environment variables; values set here win.
type Concurrency ¶
type Concurrency struct {
Limit int `json:"limit"`
Key *string `json:"key,omitempty"`
Scope string `json:"scope,omitempty"`
}
Concurrency limits how many steps of the function run at once. Key is an expression over event; Scope is "fn" (default), "env" or "account".
type Debounce ¶
Debounce waits for Period of quiet before running, with the last event. Timeout is the longest it may wait in all (zero: no limit).
type FunctionConfig ¶
type FunctionConfig struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Triggers []Trigger `json:"triggers"`
Retries *int `json:"retries,omitempty"`
Timeouts *timeoutsJSON `json:"timeouts,omitempty"`
CancelOn []cancelOnJSON `json:"cancelOn,omitempty"`
Concurrency []Concurrency `json:"concurrency,omitempty"`
Throttle *throttleJSON `json:"throttle,omitempty"`
RateLimit *rateLimitJSON `json:"rateLimit,omitempty"`
Debounce *debounceJSON `json:"debounce,omitempty"`
BatchEvents *batchEventsJSON `json:"batchEvents,omitempty"`
Priority *Priority `json:"priority,omitempty"`
Idempotency *string `json:"idempotency,omitempty"`
Singleton *Singleton `json:"singleton,omitempty"`
}
FunctionConfig is one function in the manifest, with Inngest's key names.
type FunctionOpts ¶
type FunctionOpts struct {
ID string
Name string
Retries *int
Timeouts *Timeouts
CancelOn []CancelOn
Concurrency []Concurrency
Throttle *Throttle
RateLimit *RateLimit
Debounce *Debounce
BatchEvents *BatchEvents
Priority *Priority
// Idempotency is an expression over event; one run per value.
Idempotency *string
Singleton *Singleton
}
FunctionOpts configures a function. Only ID is required.
Durations are sent to the engine as "<n>s" when they are whole seconds, else as "<n>ms".
type GenericEvent ¶
type GenericEvent[T any] struct { ID string `json:"id"` Name string `json:"name"` Data T `json:"data"` Timestamp int64 `json:"ts"` User any `json:"user,omitempty"` }
GenericEvent is an event a function receives, with typed data.
type Input ¶
type Input[T any] struct { Event GenericEvent[T] Events []GenericEvent[T] InputCtx InputCtx }
Input is what a handler gets: the trigger event, the batch (one item unless batching) and the run details.
type InputCtx ¶
type InputCtx struct {
Env string
FunctionID string
RunID string
// Attempt counts from 0.
Attempt int
MaxAttempts int
}
InputCtx says which run and attempt this is.
type MultipleTriggers ¶
type MultipleTriggers []Trigger
MultipleTriggers starts a function from any of several triggers.
type Priority ¶
type Priority struct {
Run *string `json:"run,omitempty"`
}
Priority orders waiting runs. Run is an expression giving a boost in seconds (-600 to 600).
type ServableFunction ¶
type ServableFunction interface {
// ID is the function ID without the app prefix.
ID() string
// FullyQualifiedID is "<appId>-<id>", used by step.Invoke and in
// inngest/function.failed events.
FullyQualifiedID() string
// Config is the function's manifest entry.
Config() FunctionConfig
// contains filtered or unexported methods
}
ServableFunction is a function made by CreateFunction.
func CreateFunction ¶
func CreateFunction[T any](c *Client, opts FunctionOpts, trigger Triggerable, handler Handler[T]) (ServableFunction, error)
CreateFunction defines a function and adds it to the client.
For failure handling (onFailure in TypeScript), create a second function with trigger EventTrigger("inngest/function.failed", StrPtr("event.data.function_id == '<appId>-<id>'")). Its event data holds function_id, run_id, error and event (the original trigger event).
type Trigger ¶
type Trigger struct {
Event string `json:"event,omitempty"`
If *string `json:"if,omitempty"`
Cron string `json:"cron,omitempty"`
}
Trigger starts a function: an event (with an optional "if" expression) or a cron schedule. Make one with EventTrigger or CronTrigger.
func CronTrigger ¶
CronTrigger runs the function on a cron schedule, for example "0 2 * * *" or "TZ=Africa/Lagos 0 2 * * *".
func EventTrigger ¶
EventTrigger runs the function for each event with this name. expr is an optional "if" expression over event, for example "event.data.plan == 'pro'".
type Triggerable ¶
type Triggerable interface {
// contains filtered or unexported methods
}
Triggerable is a Trigger or MultipleTriggers.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package group runs steps in parallel.
|
Package group runs steps in parallel. |
|
internal
|
|
|
core
Package core holds the parts shared by the flow, step and group packages: the wire types, the replay state of one call, and the error types.
|
Package core holds the parts shared by the flow, step and group packages: the wire types, the replay state of one call, and the error types. |
|
Package step has the durable steps a flow function calls: Run, Sleep, SleepUntil, WaitForEvent, Invoke and Send.
|
Package step has the durable steps a flow function calls: Run, Sleep, SleepUntil, WaitForEvent, Invoke and Send. |