Documentation
¶
Overview ¶
package worker provides functionality for creating and managing hatchet workers. workers are responsible for executing workflow tasks and communicating with the hatchet API.
Index ¶
- func WithWorkflows(workflows ...workflow.WorkflowBase) func(*WorkerImpl)
- type CreateOpts
- type NamedFunction
- type Worker
- type WorkerImpl
- func (w *WorkerImpl) IsPaused(ctx ...context.Context) (bool, error)
- func (w *WorkerImpl) Pause(ctx ...context.Context) error
- func (w *WorkerImpl) RegisterWorkflows(workflows ...workflow.WorkflowBase) error
- func (w *WorkerImpl) Start() (func() error, error)
- func (w *WorkerImpl) StartBlocking() error
- func (w *WorkerImpl) Unpause(ctx ...context.Context) error
- type WorkerLabels
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithWorkflows ¶ added in v0.55.26
func WithWorkflows(workflows ...workflow.WorkflowBase) func(*WorkerImpl)
WithWorkflows is a functional option that configures a worker with the specified workflows.
Types ¶
type CreateOpts ¶ added in v0.55.26
type CreateOpts struct {
// (required) the friendly name of the worker
Name string
// (optional) maximum number of concurrent runs on this worker, defaults to 100
Slots int
// (optional) labels to set on the worker
Labels WorkerLabels
// (optional) logger to use for the worker
Logger *zerolog.Logger
// (optional) log level
LogLevel string
// (optional) maximum number of concurrent runs for durable tasks, defaults to 1000
DurableSlots int
}
CreateOpts defines the options for creating a new worker.
type NamedFunction ¶
type NamedFunction struct {
ActionID string
Fn workflow.WrappedTaskFn
}
NamedFunction represents a function with its associated action ID
type Worker ¶
type Worker interface {
// Start begins worker execution in a non-blocking manner and returns a cleanup function.
// the cleanup function should be called when the worker needs to be stopped.
Start() (func() error, error)
// StartBlocking begins worker execution and blocks until the process is interrupted.
StartBlocking() error
// RegisterWorkflows registers one or more workflows with the worker.
RegisterWorkflows(workflows ...workflow.WorkflowBase) error
// IsPaused checks if all worker instances are paused
IsPaused(ctx ...context.Context) (bool, error)
// Pause pauses all worker instances
Pause(ctx ...context.Context) error
// Unpause resumes all paused worker instances
Unpause(ctx ...context.Context) error
}
Worker defines the interface for interacting with a hatchet worker.
func NewWorker ¶
func NewWorker(workersClient *features.WorkersClient, v0 *v0Client.Client, opts CreateOpts, optFns ...func(*WorkerImpl)) (Worker, error)
NewWorker creates and configures a new Worker with the provided client and options. additional functional options can be provided to further customize the worker configuration. returns the created Worker interface and any error encountered during creation.
type WorkerImpl ¶
type WorkerImpl struct {
// contains filtered or unexported fields
}
WorkerImpl is the concrete implementation of the Worker interface.
func (*WorkerImpl) IsPaused ¶
func (w *WorkerImpl) IsPaused(ctx ...context.Context) (bool, error)
IsPaused checks if all worker instances are paused
func (*WorkerImpl) Pause ¶
func (w *WorkerImpl) Pause(ctx ...context.Context) error
Pause pauses all worker instances
func (*WorkerImpl) RegisterWorkflows ¶
func (w *WorkerImpl) RegisterWorkflows(workflows ...workflow.WorkflowBase) error
RegisterWorkflows registers one or more workflows with the worker. it converts the workflows to the format expected by the underlying worker implementation and registers both the workflow definitions and their action functions. returns an error if registration fails.
func (*WorkerImpl) Start ¶
func (w *WorkerImpl) Start() (func() error, error)
Start begins worker execution in a non-blocking manner. returns a cleanup function to be called when the worker should be stopped, and any error encountered during startup.
func (*WorkerImpl) StartBlocking ¶
func (w *WorkerImpl) StartBlocking() error
StartBlocking begins worker execution and blocks until the process is interrupted. this method handles graceful shutdown via interrupt signals. returns any error encountered during startup or shutdown.
type WorkerLabels ¶
type WorkerLabels map[string]interface{}
WorkerLabels represents a map of labels that can be assigned to a worker for filtering and identification purposes.