Documentation
¶
Overview ¶
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. Users never import it; the public packages re-export what they need.
Index ¶
- Constants
- Variables
- func Decode[T any](data json.RawMessage) (T, error)
- func Duration(d time.Duration) string
- func DurationPtr(d *time.Duration) *string
- func HashStepID(id string, occurrence int) string
- func IdempotencyKeyFrom(ctx context.Context) string
- func InParallel(ctx context.Context) bool
- func IsBranchStop(r any) bool
- func IsControl(r any) bool
- func IsNoRetry(err error) bool
- func NoRetryErr(err error) error
- func RetryTime(err error) (time.Time, bool)
- func StopBranch()
- func StopRun()
- func WithParallel(ctx context.Context) context.Context
- func WithRun(ctx context.Context, r *Run) context.Context
- type Control
- type Event
- type InvokeRequest
- type LoadedMemoEntry
- type MemoEntry
- type NoRetry
- type Opcode
- type PanicError
- type RetryAt
- type Run
- func (r *Run) HasPending() bool
- func (r *Run) IdempotencyKey(hashed string) string
- func (r *Run) New(ctx context.Context, op Opcode, exec func() Opcode)
- func (r *Run) Next(userID string) (string, *MemoEntry)
- func (r *Run) Ops() []Opcode
- func (r *Run) RunIfAlone()
- func (r *Run) StepContext(ctx context.Context, hashed string) context.Context
- type RunStatePage
- type SerializedError
- type StepError
Constants ¶
const ( HeaderSignature = "X-Inngest-Signature" HeaderNoRetry = "X-Inngest-No-Retry" HeaderRetryAfter = "Retry-After" )
Header names, as in packages/protocol/src/types.ts (HEADERS).
const ( StatusDone = 200 StatusOps = 206 )
HTTP status codes of the app endpoint (STATUS in types.ts).
const ( OpStepCompleted = "StepCompleted" OpStepFailed = "StepFailed" OpStepPlanned = "StepPlanned" OpSleep = "Sleep" OpWaitForEvent = "WaitForEvent" OpSendEvent = "SendEvent" OpInvokeFunction = "InvokeFunction" )
Opcode names.
const MaxOutputBytes = 4_000_000
MaxOutputBytes is the largest step output the engine keeps (4 MB).
Variables ¶
var ErrNotInFunction = errors.New("flow: step called outside a flow function or inside another step")
ErrNotInFunction is returned by step calls made outside a flow function, or inside another step's callback.
Functions ¶
func Decode ¶
func Decode[T any](data json.RawMessage) (T, error)
Decode reads stored step data into T. A JSON null leaves the zero value.
func Duration ¶
Duration turns a Go duration into the engine's text form: "<n>s" when it is whole seconds, else "<n>ms". parseDuration in packages/protocol reads both. Anything under a millisecond is dropped.
func DurationPtr ¶
DurationPtr is Duration for an optional value: nil or zero gives nil.
func HashStepID ¶
HashStepID gives the hashed step ID: lowercase hex SHA-1 of id for the first use (occurrence 0), and of "id:N" for the Nth repeat.
func IdempotencyKeyFrom ¶
IdempotencyKeyFrom returns the key stored in a step callback's context.
func InParallel ¶
InParallel reports whether ctx is inside a group.Parallel branch.
func IsBranchStop ¶
IsBranchStop reports whether r stops only one parallel branch.
func WithParallel ¶
WithParallel marks the context of one group.Parallel branch.
Types ¶
type Control ¶
type Control struct {
// contains filtered or unexported fields
}
Control is the value the SDK panics with. Never swallow it.
type Event ¶
type Event struct {
Name string `json:"name"`
Data any `json:"data,omitempty"`
// ID makes the event idempotent: two events with the same ID are one event.
ID *string `json:"id,omitempty"`
// Timestamp is when the event happened, in ms since epoch. A future time
// schedules the run. Zero means now.
Timestamp int64 `json:"ts,omitempty"`
User any `json:"user,omitempty"`
}
Event is an event to send: to POST /e, or from step.Send.
type InvokeRequest ¶
type InvokeRequest struct {
FnID string `json:"fnId"`
RunID string `json:"runId"`
Env string `json:"env"`
Event json.RawMessage `json:"event"`
Events []json.RawMessage `json:"events"`
Memo map[string]MemoEntry `json:"memo"`
Attempt int `json:"attempt"`
MaxAttempts int `json:"maxAttempts"`
TargetStepID string `json:"targetStepId,omitempty"`
// UseAPI means the state was too big to send: Memo and Events are empty,
// and the SDK loads them from GET {base}/runs/{runId}/state.
UseAPI bool `json:"useApi,omitempty"`
}
InvokeRequest is the body of the signed POST from the engine.
type LoadedMemoEntry ¶
type LoadedMemoEntry = MemoEntry
LoadedMemoEntry is a memo entry from the run state API. It has the same { data } or { error } shape as MemoEntry.
type MemoEntry ¶
type MemoEntry struct {
Data json.RawMessage
Error *SerializedError
}
MemoEntry is a finished step: either Data or Error is set.
func (*MemoEntry) UnmarshalJSON ¶
UnmarshalJSON reads { data } or { error }. A missing data means null.
type Opcode ¶
type Opcode struct {
Op string `json:"op"`
ID string `json:"id"`
Name string `json:"name"`
// StepCompleted. Always sent for StepCompleted (null when empty).
Data json.RawMessage `json:"data,omitempty"`
// StepFailed.
Error *SerializedError `json:"error,omitempty"`
NoRetry bool `json:"noRetry,omitempty"`
RetryAt *int64 `json:"retryAt,omitempty"`
// Sleep: ms since epoch.
Until *int64 `json:"until,omitempty"`
// WaitForEvent.
Event string `json:"event,omitempty"`
Timeout any `json:"timeout,omitempty"`
Match *string `json:"match,omitempty"`
If *string `json:"if,omitempty"`
// SendEvent.
Events []Event `json:"events,omitempty"`
// InvokeFunction. Function is the full "<appId>-<functionId>". Timeout is shared
// with WaitForEvent above.
Function string `json:"function,omitempty"`
User json.RawMessage `json:"user,omitempty"`
}
Opcode is one step the SDK reports back. Op says which fields are used.
type PanicError ¶
PanicError is a panic recovered from a step.Run callback. It fails that step's attempt (the step is retried), the same as an error thrown in a TypeScript step.
func (*PanicError) Error ¶
func (e *PanicError) Error() string
type Run ¶
type Run struct {
RunID string
Target string
Now func() time.Time
// contains filtered or unexported fields
}
Run is the replay state of one call to a function.
func FromContext ¶
FromContext returns the replay state, or nil outside a flow function (and inside a step callback).
func (*Run) HasPending ¶
HasPending reports whether new steps were found.
func (*Run) IdempotencyKey ¶
IdempotencyKey is "<runId>:<hashed step id>", the same on every attempt.
func (*Run) New ¶
New is called when a step is not in the memo. op is the step's own opcode (for step.Run, a StepPlanned); exec runs a step.Run callback and returns its StepCompleted or StepFailed (nil for other steps). New never returns.
func (*Run) Next ¶
Next counts one use of the user's step ID and returns its hashed ID and its memo entry, if any.
func (*Run) Ops ¶
Ops returns the opcodes to answer with. In target mode it is the target's result (or nothing if it was not reached). Planned step.Run calls that did not run become StepPlanned.
func (*Run) RunIfAlone ¶
func (r *Run) RunIfAlone()
RunIfAlone runs the found step now when it is the only new step and it is a step.Run. Called at the end of the outer group.Parallel.
type RunStatePage ¶
type RunStatePage struct {
// Events is the run's batch. Only on the first page.
Events []json.RawMessage `json:"events,omitempty"`
Memo map[string]LoadedMemoEntry `json:"memo"`
// Next is the cursor for the next page; nil on the last page.
Next *string `json:"next"`
}
RunStatePage is one page of GET {base}/runs/{runId}/state.
type SerializedError ¶
type SerializedError struct {
Name string `json:"name"`
Message string `json:"message"`
Stack string `json:"stack,omitempty"`
}
SerializedError is an error as it travels on the wire.
func Serialize ¶
func Serialize(err error) SerializedError
Serialize turns an error into its wire form. The name is the StepError's name when there is one, else "Error".