client

package
v0.33.0-alpha.16 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 28 Imported by: 5

Documentation

Index

Constants

View Source
const (
	DefaultActionListenerRetryInterval = 5 * time.Second
	DefaultActionListenerRetryCount    = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// the worker id
	WorkerId string `json:"workerId"`

	// the tenant id
	TenantId string `json:"tenantId"`

	// the workflow run id
	WorkflowRunId string `json:"workflowRunId"`

	// the get group key run id
	GetGroupKeyRunId string `json:"getGroupKeyRunId"`

	// the job id
	JobId string `json:"jobId"`

	// the job name
	JobName string `json:"jobName"`

	// the job run id
	JobRunId string `json:"jobRunId"`

	// the step id
	StepId string `json:"stepId"`

	// the step name
	StepName string `json:"stepName"`

	// the step run id
	StepRunId string `json:"stepRunId"`

	// the action id
	ActionId string `json:"actionId"`

	// the action payload
	ActionPayload []byte `json:"actionPayload"`

	// the action type
	ActionType ActionType `json:"actionType"`

	// the count of the retry attempt
	RetryCount int32 `json:"retryCount"`
}

type ActionEvent

type ActionEvent struct {
	*Action

	// the event timestamp
	EventTimestamp *time.Time

	// the step event type
	EventType ActionEventType

	// The event payload. This must be JSON-compatible as it gets marshalled to a JSON string.
	EventPayload interface{}
}

type ActionEventResponse

type ActionEventResponse struct {
	// the tenant id
	TenantId string

	// the id of the worker
	WorkerId string
}

type ActionEventType

type ActionEventType string
const (
	ActionEventTypeUnknown   ActionEventType = "STEP_EVENT_TYPE_UNKNOWN"
	ActionEventTypeStarted   ActionEventType = "STEP_EVENT_TYPE_STARTED"
	ActionEventTypeCompleted ActionEventType = "STEP_EVENT_TYPE_COMPLETED"
	ActionEventTypeFailed    ActionEventType = "STEP_EVENT_TYPE_FAILED"
)

type ActionPayload

type ActionPayload func(target interface{}) error

ActionPayload unmarshals the action payload into the target. It also validates the resulting target.

type ActionType

type ActionType string
const (
	ActionTypeStartStepRun     ActionType = "START_STEP_RUN"
	ActionTypeCancelStepRun    ActionType = "CANCEL_STEP_RUN"
	ActionTypeStartGetGroupKey ActionType = "START_GET_GROUP_KEY"
)

type AdminClient

type AdminClient interface {
	PutWorkflow(workflow *types.Workflow, opts ...PutOptFunc) error
	ScheduleWorkflow(workflowName string, opts ...ScheduleOptFunc) error

	// RunWorkflow triggers a workflow run and returns the run id
	RunWorkflow(workflowName string, input interface{}, opts ...RunOptFunc) (string, error)

	RunChildWorkflow(workflowName string, input interface{}, opts *ChildWorkflowOpts) (string, error)

	PutRateLimit(key string, opts *types.RateLimitOpts) error
}

type ChildWorkflowOpts added in v0.18.0

type ChildWorkflowOpts struct {
	ParentId        string
	ParentStepRunId string
	ChildIndex      int
	ChildKey        *string
}

type Client

type Client interface {
	Admin() AdminClient
	Dispatcher() DispatcherClient
	Event() EventClient
	Subscribe() SubscribeClient
	API() *rest.ClientWithResponses
	TenantId() string
	Namespace() string
}

func New

func New(fs ...ClientOpt) (Client, error)

New creates a new client instance.

func NewFromConfigFile added in v0.11.0

func NewFromConfigFile(cf *client.ClientConfigFile, fs ...ClientOpt) (Client, error)

type ClientEventListener added in v0.9.0

type ClientEventListener interface {
	OnWorkflowEvent(ctx context.Context, event *WorkflowEvent) error
}

type ClientOpt

type ClientOpt func(*ClientOpts)

func InitWorkflows

func InitWorkflows() ClientOpt

func WithHostPort

func WithHostPort(host string, port int) ClientOpt

func WithLogLevel added in v0.18.1

func WithLogLevel(lvl string) ClientOpt

func WithNamespace added in v0.20.2

func WithNamespace(namespace string) ClientOpt

func WithTenantId

func WithTenantId(tenantId string) ClientOpt

func WithToken added in v0.11.0

func WithToken(token string) ClientOpt

func WithWorkflows

func WithWorkflows(files []*types.Workflow) ClientOpt

WithWorkflows sets the workflow files to use for the worker. If this is not passed in, the workflows files will be loaded from the .hatchet folder in the current directory.

type ClientOpts

type ClientOpts struct {
	// contains filtered or unexported fields
}

type DispatcherClient

type DispatcherClient interface {
	GetActionListener(ctx context.Context, req *GetActionListenerRequest) (WorkerActionListener, error)

	SendStepActionEvent(ctx context.Context, in *ActionEvent) (*ActionEventResponse, error)

	SendGroupKeyActionEvent(ctx context.Context, in *ActionEvent) (*ActionEventResponse, error)

	ReleaseSlot(ctx context.Context, stepRunId string) error

	RefreshTimeout(ctx context.Context, stepRunId string, incrementTimeoutBy string) error
}

type EventClient

type EventClient interface {
	Push(ctx context.Context, eventKey string, payload interface{}, options ...PushOpFunc) error

	PutLog(ctx context.Context, stepRunId, msg string) error

	PutStreamEvent(ctx context.Context, stepRunId string, message []byte) error
}

type GetActionListenerRequest

type GetActionListenerRequest struct {
	WorkerName string
	Services   []string
	Actions    []string
	MaxRuns    *int
}

TODO: add validator to client side

type ListenerStrategy added in v0.18.1

type ListenerStrategy string
const (
	ListenerStrategyV1 ListenerStrategy = "v1"
	ListenerStrategyV2 ListenerStrategy = "v2"
)

type PushOpFunc added in v0.25.0

type PushOpFunc func(*eventcontracts.PushEventRequest) error

func WithEventMetadata added in v0.25.0

func WithEventMetadata(metadata interface{}) PushOpFunc

type PutOptFunc

type PutOptFunc func(*putOpts)

type RunHandler added in v0.9.0

type RunHandler func(event WorkflowEvent) error

type RunOptFunc added in v0.25.0

func WithRunMetadata added in v0.25.0

func WithRunMetadata(metadata interface{}) RunOptFunc

type ScheduleOptFunc

type ScheduleOptFunc func(*scheduleOpts)

func WithInput

func WithInput(input any) ScheduleOptFunc

func WithSchedules

func WithSchedules(schedules ...time.Time) ScheduleOptFunc

type StreamEvent added in v0.19.0

type StreamEvent struct {
	Message []byte
}

type StreamHandler added in v0.19.0

type StreamHandler func(event StreamEvent) error

type SubscribeClient added in v0.19.0

type SubscribeClient interface {
	On(ctx context.Context, workflowRunId string, handler RunHandler) error

	Stream(ctx context.Context, workflowRunId string, handler StreamHandler) error

	SubscribeToWorkflowRunEvents(ctx context.Context) (*WorkflowRunsListener, error)
}

type WorkerActionListener

type WorkerActionListener interface {
	Actions(ctx context.Context) (<-chan *Action, error)

	Unregister() error
}

type WorkflowEvent added in v0.21.0

type WorkflowEvent *dispatchercontracts.WorkflowEvent

type WorkflowRunEvent added in v0.21.0

type WorkflowRunEvent *dispatchercontracts.WorkflowRunEvent

type WorkflowRunEventHandler added in v0.21.0

type WorkflowRunEventHandler func(event WorkflowRunEvent) error

type WorkflowRunsListener added in v0.21.0

type WorkflowRunsListener struct {
	// contains filtered or unexported fields
}

func (*WorkflowRunsListener) AddWorkflowRun added in v0.21.0

func (l *WorkflowRunsListener) AddWorkflowRun(
	workflowRunId string,
	handler WorkflowRunEventHandler,
) error

func (*WorkflowRunsListener) Close added in v0.21.0

func (l *WorkflowRunsListener) Close() error

func (*WorkflowRunsListener) Listen added in v0.21.0

func (l *WorkflowRunsListener) Listen(ctx context.Context) error

Directories

Path Synopsis
Package rest provides primitives to interact with the openapi HTTP API.
Package rest provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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