Documentation
¶
Overview ¶
Define workflows that can declare tasks and be run, scheduled, and so on. Transform functions into Hatchet tasks using a clean, reflection-based API.
Basic Usage ¶
client, err := hatchet.NewClient()
if err != nil {
log.Fatal(err)
}
workflow := client.NewWorkflow("my-workflow",
hatchet.WithWorkflowConcurrency(types.Concurrency{
Expression: "input.userId",
MaxRuns: 5,
}))
fmt.Printf("Workflow name: %s\n", workflow.Name()) // Includes namespace if set
task1 := workflow.NewTask("task-1", MyTaskFunction)
task2 := workflow.NewTask("task-2", MyOtherTaskFunction,
hatchet.WithParents(task1))
worker, err := client.NewWorker("worker-name", hatchet.WithWorkflows(workflow))
if err != nil {
log.Fatal(err)
}
err = worker.StartBlocking(ctx)
Examples ¶
For comprehensive examples demonstrating various Hatchet features, see:
- Basic workflow with a single task: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/simple
- Complex workflows with task dependencies: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/dag
- Conditional task execution and branching: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/conditions
- Triggered by external events: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/events
- Time-based workflow scheduling: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/cron
- Error handling and parallel execution: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/retries-concurrency
- Control execution rate per resource: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/rate-limiting
- Process multiple items efficiently: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/bulk-operations
- Nested workflow execution: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/child-workflows
- Worker affinity and state management: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/sticky-workers
- Long-running tasks with state persistence: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/durable
- Real-time data processing: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/streaming
- Task execution prioritization: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/priority
- Task timeout handling: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/timeouts
- Workflow and task cancellation: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/cancellations
- Error recovery and cleanup: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples/on-failure
View all examples: https://github.com/hatchet-dev/hatchet/tree/main/sdks/go/examples
Index ¶
- Variables
- func AndCondition(conditions ...condition.Condition) condition.Condition
- func EmitDeprecationNotice(feature, message string, start time.Time, logger *zerolog.Logger, ...) error
- func EventInto(event EventUnmarshaller, dest any) error
- func OrCondition(conditions ...condition.Condition) condition.Condition
- func ParentCondition(task *Task, expression string) condition.Condition
- func ParseSemver(v string) (int, int, int)
- func SemverLessThan(a, b string) bool
- func SleepCondition(duration time.Duration) condition.Condition
- func SupportsDurableEviction(engineVersion string) (bool, error)
- func UserEventCondition(eventKey, expression string) condition.Condition
- type BulkTriggerIdempotencyCollisionError
- type Client
- func (c *Client) CEL() *features.CELClient
- func (c *Client) Crons() *features.CronsClient
- func (c *Client) Events() v0Client.EventClient
- func (c *Client) Filters() *features.FiltersClient
- func (c *Client) GetEngineVersion(ctx context.Context) (string, error)
- func (c *Client) Logs() *features.LogsClient
- func (c *Client) Metrics() *features.MetricsClient
- func (c *Client) NewStandaloneDurableTask(name string, fn any, options ...StandaloneTaskOption) *StandaloneTask
- func (c *Client) NewStandaloneTask(name string, fn any, options ...StandaloneTaskOption) *StandaloneTask
- func (c *Client) NewWorker(name string, options ...WorkerOption) (*Worker, error)
- func (c *Client) NewWorkflow(name string, options ...WorkflowOption) *Workflow
- func (c *Client) RateLimits() *features.RateLimitsClient
- func (c *Client) Run(ctx context.Context, workflowName string, input any, opts ...RunOptFunc) (*WorkflowResult, error)
- func (c *Client) RunMany(ctx context.Context, workflowName string, inputs []RunManyOpt) ([]WorkflowRunRef, error)
- func (c *Client) RunNoWait(ctx context.Context, workflowName string, input any, opts ...RunOptFunc) (*WorkflowRunRef, error)
- func (c *Client) Runs() *features.RunsClient
- func (c *Client) Schedules() *features.SchedulesClient
- func (c *Client) Webhooks() *features.WebhooksClient
- func (c *Client) Workers() *features.WorkersClient
- func (c *Client) Workflows() *features.WorkflowsClient
- type Context
- type DeprecationError
- type DeprecationOpts
- type DesiredWorkerLabel
- type DurableContext
- type EventUnmarshaller
- type EvictionNotSupportedError
- type EvictionPolicy
- type IdempotencyCollisionError
- type IdempotencyConfig
- type NonDeterminismError
- type RunManyOpt
- type RunOptFunc
- type RunPriority
- type StandaloneTask
- func (st *StandaloneTask) Dump() (*v1.CreateWorkflowVersionRequest, []internal.NamedFunction, ...)
- func (st *StandaloneTask) GetName() string
- func (st *StandaloneTask) OnFailure(fn any)
- func (st *StandaloneTask) Run(ctx context.Context, input any, opts ...RunOptFunc) (*TaskResult, error)
- func (st *StandaloneTask) RunMany(ctx context.Context, inputs []RunManyOpt) ([]WorkflowRunRef, error)
- func (st *StandaloneTask) RunNoWait(ctx context.Context, input any, opts ...RunOptFunc) (*WorkflowRunRef, error)
- type StandaloneTaskOption
- type Task
- type TaskOption
- func WithConcurrency(concurrency ...*types.Concurrency) TaskOption
- func WithCron(cronExpressions ...string) TaskOption
- func WithDescription(description string) TaskOption
- func WithEvents(events ...string) TaskOption
- func WithEvictionPolicy(policy *EvictionPolicy) TaskOption
- func WithExecutionTimeout(timeout time.Duration) TaskOption
- func WithParents(parents ...*Task) TaskOption
- func WithRateLimits(rateLimits ...*types.RateLimit) TaskOption
- func WithRetries(retries int) TaskOption
- func WithRetryBackoff(factor float32, maxBackoffSeconds int) TaskOption
- func WithScheduleTimeout(timeout time.Duration) TaskOption
- func WithSkipIf(condition condition.Condition) TaskOption
- func WithSlotCost(cost int) TaskOption
- func WithWaitFor(condition condition.Condition) TaskOption
- type TaskResult
- type Worker
- type WorkerLabelComparator
- type WorkerOption
- func WithDurableSlots(durableSlots int) WorkerOption
- func WithLabels(labels map[string]any) WorkerOption
- func WithLogger(logger *zerolog.Logger) WorkerOption
- func WithPanicHandler(panicHandler func(ctx Context, recovered any)) WorkerOption
- func WithSlots(slots int) WorkerOption
- func WithWorkflows(workflows ...WorkflowBase) WorkerOption
- type Workflow
- func (w *Workflow) Dump() (*v1.CreateWorkflowVersionRequest, []internal.NamedFunction, ...)
- func (w *Workflow) GetName() string
- func (w *Workflow) NewDurableTask(name string, fn any, options ...TaskOption) *Task
- func (w *Workflow) NewTask(name string, fn any, options ...TaskOption) *Task
- func (w *Workflow) OnFailure(fn any)
- func (w *Workflow) Run(ctx context.Context, input any, opts ...RunOptFunc) (*WorkflowResult, error)
- func (w *Workflow) RunMany(ctx context.Context, inputs []RunManyOpt) ([]WorkflowRunRef, error)
- func (w *Workflow) RunNoWait(ctx context.Context, input any, opts ...RunOptFunc) (*WorkflowRunRef, error)
- type WorkflowBase
- type WorkflowOption
- func WithDefaultFilters(filters ...types.DefaultFilter) WorkflowOption
- func WithWorkflowConcurrency(concurrency ...types.Concurrency) WorkflowOption
- func WithWorkflowCron(cronExpressions ...string) WorkflowOption
- func WithWorkflowCronInput(input any) WorkflowOption
- func WithWorkflowDefaultPriority(priority RunPriority) WorkflowOption
- func WithWorkflowDescription(description string) WorkflowOption
- func WithWorkflowEvents(events ...string) WorkflowOption
- func WithWorkflowIdempotency(config IdempotencyConfig) WorkflowOption
- func WithWorkflowStickyStrategy(stickyStrategy types.StickyStrategy) WorkflowOption
- func WithWorkflowTaskDefaults(defaults *create.TaskDefaults) WorkflowOption
- func WithWorkflowVersion(version string) WorkflowOption
- type WorkflowResult
- type WorkflowRunRef
Constants ¶
This section is empty.
Variables ¶
var DefaultDurableTaskEvictionPolicy = &EvictionPolicy{ TTL: 15 * time.Minute, AllowCapacityEviction: true, Priority: 0, }
DefaultDurableTaskEvictionPolicy provides sensible defaults for durable task eviction.
var MinEngineVersion = struct { SlotConfig string DurableEviction string Observability string }{ SlotConfig: "v0.78.23", DurableEviction: "v0.80.0", Observability: "v0.82.0", }
MinEngineVersion defines minimum engine versions for feature support.
Functions ¶
func AndCondition ¶
AndCondition creates a condition that is satisfied when all of the provided conditions are met.
func EmitDeprecationNotice ¶ added in v0.78.27
func EmitDeprecationNotice(feature, message string, start time.Time, logger *zerolog.Logger, opts *DeprecationOpts) error
EmitDeprecationNotice emits a time-aware deprecation notice.
- feature: a short identifier for deduplication (each feature logs once).
- message: the human-readable deprecation message.
- start: the UTC time when the deprecation window began.
- logger: the zerolog logger to write to.
- opts: optional configuration; pass nil for defaults.
Returns a non-nil *DeprecationError only in phase 3 (~20% chance).
func EventInto ¶ added in v0.79.17
func EventInto(event EventUnmarshaller, dest any) error
EventInto extracts the event payload from a WaitForEvent result into dest.
event, err := ctx.WaitForEvent("approval:decision", "")
if err != nil { return err }
var data map[string]interface{}
if err := hatchet.EventInto(event, &data); err != nil { return err }
func OrCondition ¶
OrCondition creates a condition that is satisfied when any of the provided conditions are met.
func ParentCondition ¶
ParentCondition creates a condition based on a parent task's output.
func ParseSemver ¶ added in v0.78.27
ParseSemver extracts major, minor, patch from a version string like "v0.78.23". Returns (0,0,0) if parsing fails.
func SemverLessThan ¶ added in v0.78.27
SemverLessThan returns true if version a is strictly less than version b.
func SleepCondition ¶
SleepCondition creates a condition that waits for a specified duration.
func SupportsDurableEviction ¶ added in v0.83.58
SupportsDurableEviction checks whether the engine version supports durable eviction.
func UserEventCondition ¶
UserEventCondition creates a condition that waits for a user event.
Types ¶
type BulkTriggerIdempotencyCollisionError ¶ added in v0.95.0
type BulkTriggerIdempotencyCollisionError struct {
SuccessfulRunExternalIds []string
Collisions []*IdempotencyCollisionError
}
BulkTriggerIdempotencyCollisionError is returned when one or more runs in a bulk trigger collide on idempotency keys. It carries the IDs of successful runs alongside the individual collision errors.
func IsBulkTriggerIdempotencyCollisionError ¶ added in v0.95.0
func IsBulkTriggerIdempotencyCollisionError(err error) (*BulkTriggerIdempotencyCollisionError, bool)
IsBulkTriggerIdempotencyCollisionError checks if the error is a BulkTriggerIdempotencyCollisionError.
func (*BulkTriggerIdempotencyCollisionError) Error ¶ added in v0.95.0
func (e *BulkTriggerIdempotencyCollisionError) Error() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides the main interface for interacting with Hatchet.
func NewClient ¶
NewClient creates a new Hatchet client. Configuration options can be provided to customize the client behavior.
func (*Client) Crons ¶
func (c *Client) Crons() *features.CronsClient
Crons returns a client for managing cron triggers.
func (*Client) Events ¶
func (c *Client) Events() v0Client.EventClient
Events returns a client for sending and managing events.
func (*Client) Filters ¶
func (c *Client) Filters() *features.FiltersClient
Filters returns a client for managing event filters.
func (*Client) GetEngineVersion ¶ added in v0.83.58
GetEngineVersion retrieves the engine version from the server.
func (*Client) Logs ¶ added in v0.73.83
func (c *Client) Logs() *features.LogsClient
Logs returns a client for managing task logs.
func (*Client) Metrics ¶
func (c *Client) Metrics() *features.MetricsClient
Metrics returns a feature client for interacting with workflow and task metrics.
func (*Client) NewStandaloneDurableTask ¶ added in v0.71.11
func (c *Client) NewStandaloneDurableTask(name string, fn any, options ...StandaloneTaskOption) *StandaloneTask
NewStandaloneDurableTask creates a standalone durable task that can be triggered independently. This is a specialized workflow containing only one durable task, making it easier to create simple single-task workflows with durable functionality.
The function parameter must have the signature:
func(ctx hatchet.DurableContext, input any) (any, error)
Function signatures are validated at runtime using reflection.
Options can be any combination of WorkflowOption and TaskOption.
func (*Client) NewStandaloneTask ¶ added in v0.71.11
func (c *Client) NewStandaloneTask(name string, fn any, options ...StandaloneTaskOption) *StandaloneTask
NewStandaloneTask creates a standalone task that can be triggered independently. This is a specialized workflow containing only one task, making it easier to create simple single-task workflows without the workflow boilerplate.
The function parameter must have the signature:
func(ctx hatchet.Context, input any) (any, error)
Function signatures are validated at runtime using reflection.
Options can be any combination of WorkflowOption and TaskOption.
func (*Client) NewWorker ¶
func (c *Client) NewWorker(name string, options ...WorkerOption) (*Worker, error)
NewWorker creates a worker that can execute workflows.
func (*Client) NewWorkflow ¶
func (c *Client) NewWorkflow(name string, options ...WorkflowOption) *Workflow
NewWorkflow creates a new workflow definition. Workflows can be configured with triggers, events, and other options.
func (*Client) RateLimits ¶
func (c *Client) RateLimits() *features.RateLimitsClient
RateLimits returns a client for managing rate limits.
func (*Client) Run ¶
func (c *Client) Run(ctx context.Context, workflowName string, input any, opts ...RunOptFunc) (*WorkflowResult, error)
Run executes a workflow with the provided input and waits for completion.
func (*Client) RunMany ¶
func (c *Client) RunMany(ctx context.Context, workflowName string, inputs []RunManyOpt) ([]WorkflowRunRef, error)
RunMany executes multiple workflow instances with different inputs. Returns workflow run IDs that can be used to track the run statuses.
func (*Client) RunNoWait ¶
func (c *Client) RunNoWait(ctx context.Context, workflowName string, input any, opts ...RunOptFunc) (*WorkflowRunRef, error)
RunNoWait executes a workflow with the provided input without waiting for completion. Returns a workflow run reference that can be used to track the run status.
func (*Client) Runs ¶
func (c *Client) Runs() *features.RunsClient
Runs returns a client for managing workflow runs.
func (*Client) Schedules ¶
func (c *Client) Schedules() *features.SchedulesClient
Schedules returns a client for managing scheduled workflow runs.
func (*Client) Webhooks ¶ added in v0.77.20
func (c *Client) Webhooks() *features.WebhooksClient
Webhooks returns a client for managing webhooks.
func (*Client) Workers ¶
func (c *Client) Workers() *features.WorkersClient
Workers returns a client for managing workers.
func (*Client) Workflows ¶
func (c *Client) Workflows() *features.WorkflowsClient
Workflows returns a client for managing workflow definitions.
type Context ¶
type Context = pkgWorker.HatchetContext
Context represents the execution context passed to task functions. It provides access to workflow metadata, retry information, and other execution details.
type DeprecationError ¶ added in v0.78.27
DeprecationError is returned when a deprecation grace period has expired.
func (*DeprecationError) Error ¶ added in v0.78.27
func (e *DeprecationError) Error() string
type DeprecationOpts ¶ added in v0.78.27
type DeprecationOpts struct {
// WarnWindow is how long after start the notice is a warning.
// Defaults to 90 days if zero.
WarnWindow time.Duration
// ErrorWindow is how long after start the notice is an error log.
// After this window, calls have a 20% chance of returning an error.
// If zero (default), the error/raise phase is never reached — the notice
// stays at error-level logging indefinitely.
ErrorWindow time.Duration
}
DeprecationOpts provides optional configuration for EmitDeprecationNotice.
type DesiredWorkerLabel ¶ added in v0.79.15
type DesiredWorkerLabel = types.DesiredWorkerLabel
type DurableContext ¶
type DurableContext = pkgWorker.DurableHatchetContext
DurableContext represents the execution context for durable tasks. It extends Context with additional methods for durable operations like SleepFor.
type EventUnmarshaller ¶ added in v0.79.17
EventUnmarshaller is implemented by the result of DurableContext.WaitForEvent. Use EventInto to extract the event payload.
type EvictionNotSupportedError ¶ added in v0.83.58
type EvictionNotSupportedError struct {
EngineVersion string
}
EvictionNotSupportedError is returned when an eviction policy is configured against an engine version that does not support durable-task eviction.
func IsEvictionNotSupportedError ¶ added in v0.83.58
func IsEvictionNotSupportedError(err error) (*EvictionNotSupportedError, bool)
IsEvictionNotSupportedError reports whether err is an EvictionNotSupportedError.
func (*EvictionNotSupportedError) Error ¶ added in v0.83.58
func (e *EvictionNotSupportedError) Error() string
type EvictionPolicy ¶ added in v0.83.58
type EvictionPolicy struct {
// TTL is the maximum continuous waiting duration before TTL-eligible eviction.
// A zero value means no TTL-based eviction.
TTL time.Duration
// AllowCapacityEviction controls whether this task may be evicted under durable-slot pressure.
AllowCapacityEviction bool
// Priority determines eviction order when multiple candidates exist.
// Lower values are evicted first.
Priority int
}
EvictionPolicy configures how durable tasks are evicted from worker slots when they are in a waiting state (e.g. sleeping, waiting for events, waiting for children).
type IdempotencyCollisionError ¶ added in v0.95.0
type IdempotencyCollisionError struct {
ExistingRunExternalId string
}
IdempotencyCollisionError is returned when an idempotency key collision occurs. It contains the ID of the existing run that claimed the key.
func IsIdempotencyCollisionError ¶ added in v0.95.0
func IsIdempotencyCollisionError(err error) (*IdempotencyCollisionError, bool)
IsIdempotencyCollisionError checks if the error is an IdempotencyCollisionError.
func (*IdempotencyCollisionError) Error ¶ added in v0.95.0
func (e *IdempotencyCollisionError) Error() string
type IdempotencyConfig ¶ added in v0.95.0
type IdempotencyConfig struct {
// Expression is a CEL expression evaluated against the workflow input to produce an idempotency key.
Expression string
// TTL is the duration during which duplicate runs with the same key are rejected.
TTL time.Duration
}
IdempotencyConfig configures idempotency behavior for a workflow or standalone task. When set, runs triggered with the same computed key within the TTL window return an IdempotencyCollisionError instead of creating a new run.
type NonDeterminismError ¶ added in v0.83.58
type NonDeterminismError struct {
TaskExternalID string
Message string
NodeID int64
InvocationCount int32
}
NonDeterminismError is returned when a durable task replay detects non-deterministic behavior.
func IsNonDeterminismError ¶ added in v0.83.58
func IsNonDeterminismError(err error) (*NonDeterminismError, bool)
IsNonDeterminismError checks if the error is a NonDeterminismError and returns it if so.
func (*NonDeterminismError) Error ¶ added in v0.83.58
func (e *NonDeterminismError) Error() string
type RunManyOpt ¶
type RunManyOpt struct {
Input any
Opts []RunOptFunc
}
RunManyOpt is a type that represents the options for running multiple instances of a workflow with different inputs and options.
type RunOptFunc ¶
type RunOptFunc func(*runOpts)
func WithDesiredWorkerLabels ¶ added in v0.79.15
func WithDesiredWorkerLabels(labels map[string]*DesiredWorkerLabel) RunOptFunc
WithDesiredWorkerLabels sets desired worker labels for routing the workflow run to specific workers.
func WithRunKey ¶ added in v0.73.15
func WithRunKey(key string) RunOptFunc
WithRunKey sets the key for the child workflow run.
func WithRunMetadata ¶
func WithRunMetadata(metadata map[string]string) RunOptFunc
WithRunMetadata sets the additional metadata for the workflow run.
func WithRunPriority ¶ added in v0.72.2
func WithRunPriority(priority RunPriority) RunOptFunc
WithRunPriority sets the priority for the workflow run.
func WithRunSticky ¶ added in v0.73.15
func WithRunSticky(sticky bool) RunOptFunc
WithRunSticky enables stickiness for the child workflow run.
type RunPriority ¶ added in v0.71.2
type RunPriority = features.RunPriority
type StandaloneTask ¶ added in v0.71.11
type StandaloneTask struct {
// contains filtered or unexported fields
}
StandaloneTask represents a single task that runs independently without a workflow wrapper. It's essentially a specialized workflow containing only one task.
func (*StandaloneTask) Dump ¶ added in v0.71.11
func (st *StandaloneTask) Dump() (*v1.CreateWorkflowVersionRequest, []internal.NamedFunction, []internal.NamedFunction, internal.WrappedTaskFn)
Dump implements the WorkflowBase interface for internal use.
func (*StandaloneTask) GetName ¶ added in v0.71.11
func (st *StandaloneTask) GetName() string
GetName returns the name of the standalone task.
func (*StandaloneTask) OnFailure ¶ added in v0.73.29
func (st *StandaloneTask) OnFailure(fn any)
OnFailure sets a failure handler for the standalone task. The handler will be called when the standalone task fails.
func (*StandaloneTask) Run ¶ added in v0.71.11
func (st *StandaloneTask) Run(ctx context.Context, input any, opts ...RunOptFunc) (*TaskResult, error)
Run executes the standalone task with the provided input and waits for completion.
func (*StandaloneTask) RunMany ¶ added in v0.73.15
func (st *StandaloneTask) RunMany(ctx context.Context, inputs []RunManyOpt) ([]WorkflowRunRef, error)
RunMany executes multiple standalone task instances with different inputs. Returns workflow run IDs that can be used to track the run statuses.
func (*StandaloneTask) RunNoWait ¶ added in v0.71.11
func (st *StandaloneTask) RunNoWait(ctx context.Context, input any, opts ...RunOptFunc) (*WorkflowRunRef, error)
RunNoWait executes the standalone task with the provided input without waiting for completion. Returns a workflow run reference that can be used to track the run status.
type StandaloneTaskOption ¶ added in v0.71.11
type StandaloneTaskOption any
StandaloneTaskOption represents options that can be applied to standalone tasks. This interface allows both WorkflowOption and TaskOption to be used interchangeably.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task represents a task reference for building DAGs and conditions.
type TaskOption ¶
type TaskOption func(*taskConfig)
TaskOption configures a task instance.
func WithConcurrency ¶
func WithConcurrency(concurrency ...*types.Concurrency) TaskOption
WithConcurrency sets concurrency limits for task execution.
func WithCron ¶
func WithCron(cronExpressions ...string) TaskOption
WithCron configures standalone tasks to run on a cron schedule. Only applicable to standalone tasks, not workflow tasks.
func WithDescription ¶ added in v0.71.11
func WithDescription(description string) TaskOption
WithDescription sets a human-readable description for the task.
func WithEvents ¶
func WithEvents(events ...string) TaskOption
WithEvents configures standalone tasks to trigger on specific events. Only applicable to standalone tasks, not workflow tasks.
func WithEvictionPolicy ¶ added in v0.83.58
func WithEvictionPolicy(policy *EvictionPolicy) TaskOption
WithEvictionPolicy sets the eviction policy for a durable task.
func WithExecutionTimeout ¶ added in v0.71.5
func WithExecutionTimeout(timeout time.Duration) TaskOption
WithExecutionTimeout sets the maximum execution duration for a task.
func WithParents ¶
func WithParents(parents ...*Task) TaskOption
WithParents sets parent task dependencies.
func WithRateLimits ¶
func WithRateLimits(rateLimits ...*types.RateLimit) TaskOption
WithRateLimits sets rate limiting for task execution.
func WithRetries ¶
func WithRetries(retries int) TaskOption
WithRetries sets the number of retry attempts for failed tasks.
func WithRetryBackoff ¶
func WithRetryBackoff(factor float32, maxBackoffSeconds int) TaskOption
WithRetryBackoff configures exponential backoff for task retries.
func WithScheduleTimeout ¶ added in v0.71.5
func WithScheduleTimeout(timeout time.Duration) TaskOption
WithScheduleTimeout sets the maximum time a task can wait to be scheduled.
func WithSkipIf ¶
func WithSkipIf(condition condition.Condition) TaskOption
WithSkipIf sets a condition that will skip the task if met.
func WithSlotCost ¶ added in v0.94.15
func WithSlotCost(cost int) TaskOption
WithSlotCost sets the number of default worker slots this task consumes. A normal task consumes one. Set it higher for a task that needs more memory or CPU, so a worker runs fewer of them at once. A single worker must have that many free slots to run it. Durable tasks ignore it. Panics if cost is not positive.
func WithWaitFor ¶
func WithWaitFor(condition condition.Condition) TaskOption
WithWaitFor sets a condition that must be met before the task executes.
type TaskResult ¶ added in v0.71.11
type TaskResult struct {
RunId string
// contains filtered or unexported fields
}
TaskResult wraps a single task's output and provides type-safe conversion methods.
func (*TaskResult) Into ¶ added in v0.71.11
func (tr *TaskResult) Into(dest any) error
Into converts the task result into the provided destination using JSON marshal/unmarshal. The destination should be a pointer to the desired type.
Example usage:
var output MyOutputType err := taskResult.Into(&output)
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker represents a worker that can execute workflows.
func (*Worker) StartBlocking ¶
StartBlocking starts the worker and blocks until it completes. This is a convenience method for common usage patterns.
func (*Worker) Use ¶ added in v0.82.0
func (w *Worker) Use(mws ...worker.MiddlewareFunc)
Use registers middleware functions on the worker. Middleware functions are called in order for each step run execution.
type WorkerLabelComparator ¶ added in v0.79.15
type WorkerLabelComparator = types.WorkerLabelComparator
type WorkerOption ¶
type WorkerOption func(*workerConfig)
WorkerOption configures a worker instance.
func WithDurableSlots ¶
func WithDurableSlots(durableSlots int) WorkerOption
WithDurableSlots sets the maximum number of concurrent durable task runs.
func WithLabels ¶
func WithLabels(labels map[string]any) WorkerOption
WithLabels assigns labels to the worker for task routing.
func WithLogger ¶
func WithLogger(logger *zerolog.Logger) WorkerOption
WithLogger sets a custom logger for the worker.
func WithPanicHandler ¶ added in v0.73.0
func WithPanicHandler(panicHandler func(ctx Context, recovered any)) WorkerOption
WithPanicHandler sets a custom panic handler for the worker.
recovered is the non-nil value that was obtained after calling recover()
func WithSlots ¶
func WithSlots(slots int) WorkerOption
WithSlots sets the maximum number of concurrent workflow runs.
func WithWorkflows ¶
func WithWorkflows(workflows ...WorkflowBase) WorkerOption
WithWorkflows registers workflows and standalone tasks with the worker. Both workflows and standalone tasks implement the WorkflowBase interface.
type Workflow ¶
type Workflow struct {
// contains filtered or unexported fields
}
Workflow defines a Hatchet workflow, which can then declare tasks and be run, scheduled, and so on.
func (*Workflow) Dump ¶
func (w *Workflow) Dump() (*v1.CreateWorkflowVersionRequest, []internal.NamedFunction, []internal.NamedFunction, internal.WrappedTaskFn)
Dump implements the WorkflowBase interface for internal use.
func (*Workflow) GetName ¶
GetName returns the resolved workflow name (including namespace if applicable).
func (*Workflow) NewDurableTask ¶
func (w *Workflow) NewDurableTask(name string, fn any, options ...TaskOption) *Task
NewDurableTask transforms a function into a durable Hatchet task that runs as part of a workflow.
The function parameter must have the signature:
func(ctx hatchet.DurableContext, input any) (any, error)
Function signatures are validated at runtime using reflection.
func (*Workflow) NewTask ¶
func (w *Workflow) NewTask(name string, fn any, options ...TaskOption) *Task
NewTask transforms a function into a Hatchet task that runs as part of a workflow.
The function parameter must have the signature:
func(ctx hatchet.Context, input any) (any, error)
Function signatures are validated at runtime using reflection.
func (*Workflow) OnFailure ¶
OnFailure sets a failure handler for the workflow. The handler will be called when any task in the workflow fails.
func (*Workflow) Run ¶
func (w *Workflow) Run(ctx context.Context, input any, opts ...RunOptFunc) (*WorkflowResult, error)
Run executes the workflow with the provided input and waits for completion.
func (*Workflow) RunMany ¶ added in v0.73.15
func (w *Workflow) RunMany(ctx context.Context, inputs []RunManyOpt) ([]WorkflowRunRef, error)
RunMany executes multiple workflow instances with different inputs.
func (*Workflow) RunNoWait ¶
func (w *Workflow) RunNoWait(ctx context.Context, input any, opts ...RunOptFunc) (*WorkflowRunRef, error)
RunNoWait executes the workflow with the provided input without waiting for completion. Returns a workflow run reference that can be used to track the run status.
type WorkflowBase ¶ added in v0.73.29
type WorkflowBase interface {
GetName() string
OnFailure(fn any)
// Internal use only. Will be removed in the future.
Dump() (*v1.CreateWorkflowVersionRequest, []internal.NamedFunction, []internal.NamedFunction, internal.WrappedTaskFn)
}
type WorkflowOption ¶
type WorkflowOption func(*workflowConfig)
WorkflowOption configures a workflow instance.
func WithDefaultFilters ¶ added in v0.88.7
func WithDefaultFilters(filters ...types.DefaultFilter) WorkflowOption
WithDefaultFilters sets default filters for event-triggered workflows or standalone tasks.
func WithWorkflowConcurrency ¶
func WithWorkflowConcurrency(concurrency ...types.Concurrency) WorkflowOption
WithWorkflowConcurrency sets concurrency controls for the workflow.
func WithWorkflowCron ¶
func WithWorkflowCron(cronExpressions ...string) WorkflowOption
WithWorkflowCron configures the workflow to run on a cron schedule. Multiple cron expressions can be provided.
func WithWorkflowCronInput ¶ added in v0.73.58
func WithWorkflowCronInput(input any) WorkflowOption
WithWorkflowCronInput sets the input for cron workflows.
func WithWorkflowDefaultPriority ¶ added in v0.73.15
func WithWorkflowDefaultPriority(priority RunPriority) WorkflowOption
WithWorkflowDefaultPriority sets the default priority for the workflow.
func WithWorkflowDescription ¶
func WithWorkflowDescription(description string) WorkflowOption
WithWorkflowDescription sets a human-readable description for the workflow.
func WithWorkflowEvents ¶
func WithWorkflowEvents(events ...string) WorkflowOption
WithWorkflowEvents configures the workflow to trigger on specific events.
func WithWorkflowIdempotency ¶ added in v0.95.0
func WithWorkflowIdempotency(config IdempotencyConfig) WorkflowOption
WithWorkflowIdempotency configures idempotency for the workflow. When set, runs triggered with the same computed key within the TTL window return an IdempotencyCollisionError instead of creating a new run.
func WithWorkflowStickyStrategy ¶ added in v0.73.15
func WithWorkflowStickyStrategy(stickyStrategy types.StickyStrategy) WorkflowOption
WithWorkflowStickyStrategy sets the sticky strategy for the workflow.
func WithWorkflowTaskDefaults ¶ added in v0.71.5
func WithWorkflowTaskDefaults(defaults *create.TaskDefaults) WorkflowOption
WithWorkflowTaskDefaults sets the default configuration for all tasks in the workflow.
func WithWorkflowVersion ¶
func WithWorkflowVersion(version string) WorkflowOption
WithWorkflowVersion sets the version identifier for the workflow.
type WorkflowResult ¶ added in v0.71.11
type WorkflowResult struct {
RunId string
// contains filtered or unexported fields
}
WorkflowResult wraps workflow execution results and provides type-safe conversion methods.
func (*WorkflowResult) Raw ¶ added in v0.71.11
func (wr *WorkflowResult) Raw() any
Raw returns the raw workflow result as interface{}.
func (*WorkflowResult) TaskOutput ¶ added in v0.71.11
func (wr *WorkflowResult) TaskOutput(taskName string) *TaskResult
TaskOutput extracts the output of a specific task from the workflow result. Returns a TaskResult that can be used to convert the task output into the desired type.
Example usage:
taskResult := workflowResult.TaskOutput("myTask")
var output MyOutputType
err := taskResult.Into(&output)
type WorkflowRunRef ¶ added in v0.73.15
type WorkflowRunRef struct {
RunId string
// contains filtered or unexported fields
}
WorkflowRunRef is a type that represents a reference to a workflow run.
func (*WorkflowRunRef) Result ¶ added in v0.73.15
func (wr *WorkflowRunRef) Result() (*WorkflowResult, error)
V0Workflow returns the underlying v0Client.Workflow.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
affinity-workers
command
|
|
|
bulk-operations
command
|
|
|
bulk-operations/cancel
command
|
|
|
cancellations
command
|
|
|
child-workflows
command
|
|
|
concurrency
command
|
|
|
conditions
command
|
|
|
cron
command
|
|
|
dag
command
|
|
|
durable/event
command
|
|
|
durable/eviction
command
|
|
|
durable/eviction/emit
command
|
|
|
durable/eviction/trigger
command
|
|
|
durable/sleep
command
|
|
|
events
command
|
|
|
idempotency
command
|
|
|
logs_test
command
|
|
|
manual-slot-release
command
|
|
|
on-event
command
|
|
|
on-failure
command
|
|
|
opentelemetry_instrumentation
command
|
|
|
panic-handler
command
|
|
|
priority
command
|
|
|
rate-limiting
command
|
|
|
retries
command
|
|
|
retries-concurrency
command
|
|
|
run-with-metadata
command
|
|
|
runtime-affinity
command
|
|
|
sdk-migration
command
|
|
|
setup
command
|
|
|
simple
command
|
|
|
slot-cost
command
|
|
|
streaming/consumer
command
|
|
|
streaming/server
command
|
|
|
streaming/worker
command
|
|
|
stubs
command
|
|
|
timeouts
command
|
|
|
webhooks
command
|
|
|
with-workflows
command
|
|
|
package features provides functionality for interacting with hatchet features.
|
package features provides functionality for interacting with hatchet features. |
|
Package internal provides internal functionality for the Hatchet Go SDK
|
Package internal provides internal functionality for the Hatchet Go SDK |
|
Package opentelemetry provides OpenTelemetry instrumentation for the Hatchet Go SDK.
|
Package opentelemetry provides OpenTelemetry instrumentation for the Hatchet Go SDK. |