worker

package
v0.65.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 9 Imported by: 3

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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(ctx context.Context) 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 WorkerOpts) (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(ctx context.Context) 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.

func (*WorkerImpl) Unpause

func (w *WorkerImpl) Unpause(ctx context.Context) error

Unpause resumes all paused worker instances

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.

type WorkerOpts

type WorkerOpts struct {
	// (required) the friendly name of the worker
	Name string

	// (optional) a list of workflows to register on the worker. If not provided, the worker will not run any workflows.
	Workflows []workflow.WorkflowBase

	// (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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL