Documentation
¶
Overview ¶
Package workflow provides functionality for defining, managing, and executing workflows in Hatchet. A workflow is a collection of tasks with defined dependencies and execution logic.
Index ¶
- func RunChildWorkflow[I any, O any](ctx worker.HatchetContext, workflow WorkflowDeclaration[I, O], input I, ...) (*O, error)
- type CreateOpts
- type DurableWrappedTaskFn
- type NamedFunction
- type RunAsChildOpts
- type RunOpts
- type TaskWithSpecificOutput
- type WorkflowBase
- type WorkflowDeclaration
- type WrappedTaskFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunChildWorkflow ¶
func RunChildWorkflow[I any, O any]( ctx worker.HatchetContext, workflow WorkflowDeclaration[I, O], input I, opts ...RunOpts, ) (*O, error)
RunChildWorkflow is a helper function to run a child workflow with full type safety It takes the parent context, the child workflow declaration, and input Returns the typed output of the child workflow
Types ¶
type CreateOpts ¶ added in v0.55.26
type CreateOpts[I any] struct { // (required) The friendly name of the workflow Name string // (optional) The version of the workflow Version string // (optional) The human-readable description of the workflow Description string // (optional) The event names that trigger the workflow OnEvents []string // (optional) The cron expressions for scheduled workflow runs OnCron []string // (optional) Concurrency settings to control parallel execution Concurrency *types.Concurrency // (optional) Task to execute when workflow fails OnFailureTask *task.OnFailureTaskDeclaration[I] // (optional) Strategy for sticky execution of workflow runs StickyStrategy *types.StickyStrategy // (optional) Default settings for all tasks within this workflow TaskDefaults *task.TaskDefaults }
CreateOpts contains configuration options for creating a new workflow.
type DurableWrappedTaskFn ¶
type DurableWrappedTaskFn func(ctx worker.DurableHatchetContext) (interface{}, error)
DurableWrappedTaskFn represents a durable task function that can be executed by the Hatchet worker. It takes a DurableHatchetContext and returns an interface{} result and an error.
type NamedFunction ¶
type NamedFunction struct {
ActionID string
Fn WrappedTaskFn
}
NamedFunction represents a function with its associated action ID
type RunAsChildOpts ¶
type RunOpts ¶
type RunOpts struct {
AdditionalMetadata *map[string]interface{}
// contains filtered or unexported fields
}
type TaskWithSpecificOutput ¶
type TaskWithSpecificOutput[I any, T any] struct { Name string Fn func(input I, ctx worker.HatchetContext) (*T, error) }
Define a TaskDeclaration with specific output type
type WorkflowBase ¶
type WorkflowBase interface {
// Dump converts the workflow declaration into a protobuf request and function mappings.
// Returns the workflow definition, regular task functions, durable task functions, and the on failure task function.
Dump() (*contracts.CreateWorkflowVersionRequest, []NamedFunction, []NamedFunction, WrappedTaskFn)
}
WorkflowBase defines the common interface for all workflow types.
type WorkflowDeclaration ¶
type WorkflowDeclaration[I any, O any] interface { WorkflowBase // Task registers a task that will be executed as part of the workflow Task(opts task.CreateOpts[I]) *task.TaskDeclaration[I] // DurableTask registers a durable task that will be executed as part of the workflow. // Durable tasks can be paused and resumed across workflow runs, making them suitable // for long-running operations or tasks that require human intervention. DurableTask(opts task.CreateOpts[I]) *task.DurableTaskDeclaration[I] // Run executes the workflow with the provided input. Run(input I, opts ...RunOpts) (*O, error) // RunChild executes a child workflow with the provided input. RunAsChild(ctx worker.HatchetContext, input I, opts ...RunAsChildOpts) (*O, error) // RunNoWait executes the workflow with the provided input without waiting for it to complete. // Instead it returns a run ID that can be used to check the status of the workflow. RunNoWait(input I, opts ...RunOpts) (*v0Client.Workflow, error) // Cron schedules the workflow to run on a regular basis using a cron expression. Cron(name string, cronExpr string, input I, opts ...RunOpts) (*rest.CronWorkflows, error) // Schedule schedules the workflow to run at a specific time. Schedule(triggerAt time.Time, input I, opts ...RunOpts) (*rest.ScheduledWorkflows, error) // Get retrieves the current state of the workflow. Get() (*rest.Workflow, error) // Metrics retrieves metrics for this workflow. Metrics(opts ...rest.WorkflowGetMetricsParams) (*rest.WorkflowMetrics, error) // QueueMetrics retrieves queue metrics for this workflow. QueueMetrics(opts ...rest.TenantGetQueueMetricsParams) (*rest.TenantGetQueueMetricsResponse, error) }
WorkflowDeclaration represents a workflow with input type I and output type O. It provides methods to define tasks, specify dependencies, and execute the workflow.
func NewWorkflowDeclaration ¶
func NewWorkflowDeclaration[I any, O any](opts CreateOpts[I], v0 *v0Client.Client) WorkflowDeclaration[I, O]
NewWorkflowDeclaration creates a new workflow declaration with the specified options and client. The workflow will have input type I and output type O.
type WrappedTaskFn ¶
type WrappedTaskFn func(ctx worker.HatchetContext) (interface{}, error)
WrappedTaskFn represents a task function that can be executed by the Hatchet worker. It takes a HatchetContext and returns an interface{} result and an error.