ops

package
v0.0.65 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package types defines interfaces for activities that can be consumed by recipe-worker

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear removes all operations from the registry

func CommandMain

func CommandMain(op RegisterableOp)

CommandMain executes a single-step RegisterableOp using the extension process contract.

func DecodeHookMapDecoder

func DecodeHookMapDecoder(from reflect.Type, to reflect.Type, data any) (any, error)

func DecodeWithJsonTags

func DecodeWithJsonTags[T any](data map[string]interface{}, input *T) error

func Register

func Register(ops ...RegisterableOp)

Register adds a new operatio(s)) to the registry

func Replace

func Replace(ops ...RegisterableOp)

Replace atomically swaps the registry contents with the provided operations.

func RunAsCommand

func RunAsCommand(op RegisterableOp) int

RunAsCommand executes a single-step RegisterableOp using JSON stdin/stdout.

func SetNextTaskAlternate added in v0.0.56

func SetNextTaskAlternate(deps OpDependencies, alternate jobworkflow.TaskAlternate) error

SetNextTaskAlternate declares another handler for the next logical substep. The absolute eligibility time is persisted with the current activity outcome.

func Size

func Size() int

Size returns the number of registered operations

func SuspendExecution added in v0.0.52

func SuspendExecution(deps OpDependencies, patch execution.Requirements) error

SuspendExecution attaches a continuation directive to the durable activity result. Return normally after requesting it; dependent recipe work resumes only after a new execution invocation. It does not migrate in-memory work.

Types

type ActivityHandlerV2

type ActivityHandlerV2[In OpInputType, Out OpOutputType] func(deps OpDependencies, ctx context.Context, in In) (Out, error)

ActivityHandlerV2 defines the signature for activity handlers that accept an invocation descriptor.

type GitExecutionContext

type GitExecutionContext struct {
	Workspace        *contextual.WorkspaceContext `json:"workspace,omitempty"`
	CellResolution   *cellref.Context             `json:"cell_resolution,omitempty"`
	RestoreArtifact  *jobdb.ArtifactKey           `json:"restore_artifact,omitempty"`
	BaseRepo         string                       `json:"base_repo,omitempty"`
	BaseRef          string                       `json:"base_ref,omitempty"`
	ResolvedBaseHash string                       `json:"resolved_base_hash,omitempty"`
	RecipeSourceRepo string                       `json:"recipe_source_repo,omitempty"`
	RecipeSourceRef  string                       `json:"recipe_source_ref,omitempty"`
	PersistHash      string                       `json:"persist_hash,omitempty"`
	ParentHash       string                       `json:"parent_hash,omitempty"`
	CellName         string                       `json:"cell_name,omitempty"`
	GitAuthor        string                       `json:"git_author,omitempty"`
	NodePath         string                       `json:"node_path,omitempty"`
	InvokeSeq        int64                        `json:"invoke_seq,omitempty"`
	InvokeHash       string                       `json:"invoke_hash,omitempty"`
	WorktreePath     string                       `json:"worktree_path,omitempty"`
}

GitExecutionContext exposes the current execution workspace and git metadata to ops without requiring user-facing inputs to mirror internal runtime state.

type HasManagmentService

type HasManagmentService interface {
	GetManagementService() ManagementService
}

type JobTool

type JobTool interface {
	GetJobKey() jobdb.JobKey
	AwaitJobs(jobIds ...string) error
}

JobTool provides a way to influence the current jobs operation. It is separate from workflowcontrol, which is about running jobs independent of this jobs context.

type ManagementService

type ManagementService interface {
	// GetRoutes returns HTTP routes this service provides
	GetRoutes() []Route

	// Initialize with injected dependencies
	Initialize(deps ServiceDependencies2) error
	Close()
}

ManagementService provides HTTP endpoints for managing input requests

type MapDecoder

type MapDecoder interface {
	DecodeFromMap(input any) error
}

type OpBuilder

type OpBuilder interface {
	WithType(t string) OpBuilder
	WithDescription(desc string) OpBuilder
	WithVersion(ver string) OpBuilder
	WithDefaultTimeout(d time.Duration) OpBuilder
	WithAcceptsArtifacts(accept bool) OpBuilder
	AddStep(name string, step Step) OpBuilder
	WithManagementService(svc ManagementService) OpBuilder
	Build() (RegisterableOp, error)
	BuildOrPanic() RegisterableOp
}

OpBuilder builds a multi-step RegisterableOp.

func NewOp

func NewOp() OpBuilder

type OpDependencies

type OpDependencies interface {
	Objects() *objects.Store
	Database() *gorm.DB
	WorkflowControl() workflowctl.WorkflowControl
	GetInputArtifacts() []jobdb.Artifact
	AddOutputArtifact(jobdb.Artifact) error
	AddExternalArtifact(name string, url string, expand bool) error
	GetOutputArtifacts() []jobdb.Artifact
	GetExternalArtifacts() map[string]recipeartifacts.Ref
	WorktreePath() string
	GitContext() GitExecutionContext
	CurrentJobContext() jobcontext.Current
	ProtectedEnv() map[string]string
	JobTool() JobTool
	FindArtifact(key jobdb.ArtifactKey) (jobdb.Artifact, error)
	SetNextTaskType(taskType string)
}

type OpDependenciesBuilder

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

func NewOpDependenciesBuilder

func NewOpDependenciesBuilder() *OpDependenciesBuilder

NewOpDependenciesBuilder creates a new, empty builder instance.

func (*OpDependenciesBuilder) Build

func (*OpDependenciesBuilder) WithArtifacts

func (b *OpDependenciesBuilder) WithArtifacts(initialArtifacts []jobdb.Artifact) *OpDependenciesBuilder

func (*OpDependenciesBuilder) WithCurrentJobContext added in v0.0.42

func (b *OpDependenciesBuilder) WithCurrentJobContext(ctx jobcontext.Current) *OpDependenciesBuilder

func (*OpDependenciesBuilder) WithDatabase

func (b *OpDependenciesBuilder) WithDatabase(db *gorm.DB) *OpDependenciesBuilder

func (*OpDependenciesBuilder) WithGitContext

func (*OpDependenciesBuilder) WithJobTool

func (*OpDependenciesBuilder) WithObjects added in v0.0.56

func (b *OpDependenciesBuilder) WithObjects(store *objects.Store) *OpDependenciesBuilder

func (*OpDependenciesBuilder) WithOperationPaths added in v0.0.8

func (b *OpDependenciesBuilder) WithOperationPaths(paths OperationPaths) *OpDependenciesBuilder

func (*OpDependenciesBuilder) WithProtectedEnv added in v0.0.42

func (b *OpDependenciesBuilder) WithProtectedEnv(env map[string]string) *OpDependenciesBuilder

func (*OpDependenciesBuilder) WithTaskContext

func (*OpDependenciesBuilder) WithWorkflowControl

func (*OpDependenciesBuilder) WithWorktreePath

func (b *OpDependenciesBuilder) WithWorktreePath(path string) *OpDependenciesBuilder

type OpExecutor

type OpExecutor interface {
}

type OpInputType

type OpInputType = any

type OpMetadata

type OpMetadata struct {
	Type             string        // Unique identifier for the activity type
	Description      string        // Detailed description
	Version          string        // Semantic version
	DefaultTimeout   time.Duration // Default execution timeout
	AcceptsArtifacts bool          // Whether the op accepts inbox artifact bindings
}

OpMetadata describes the activity for registration and documentation. Task-level DisallowAsTask is handled on TaskStep.

type OpOutputType

type OpOutputType = any

type OperationPathProvider added in v0.0.8

type OperationPathProvider interface{ OperationPaths() OperationPaths }

type OperationPaths added in v0.0.8

type OperationPaths struct {
	Workdir      string
	WorktreePath string
	Inbox        string
	Outbox       string
}

OperationPaths are paths visible to operations in the worker environment.

type RawMessageOrStruct

type RawMessageOrStruct = any

type RegisterableOp

type RegisterableOp interface {
	GetMetadata() OpMetadata
	GetName() string
	TaskChain() []TaskStep
	GetManagementService() ManagementService
	// contains filtered or unexported methods
}

RegisterableOp defines the contract for ops that can be consumed by external systems like recipe-worker via YAML definitions. Multi-step aware: execution happens per TaskStep in TaskChain.

func Get

func Get(name string) (RegisterableOp, bool)

Get retrieves an operation by name with existence check

func List

func List() []RegisterableOp

List returns all registered operation names

func NewActivityMappedOpV2

func NewActivityMappedOpV2[In any, Out any](metadata OpMetadata, handler ActivityHandlerV2[In, Out]) RegisterableOp

Compatibility helpers: legacy constructors delegate to the builder with a single step.

func NewActivityMappedOpWithProviderV2

func NewActivityMappedOpWithProviderV2[In any, Out any](metadata OpMetadata, handler ActivityHandlerV2[In, Out], getInputStruct func() interface{}) RegisterableOp

type Route

type Route struct {
	Method  string
	Path    string
	Handler http.HandlerFunc
}

Route represents an HTTP route

type SSEEvent

type SSEEvent struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data"`
}

SSEEvent represents a server-sent event

type SSEManager

type SSEManager interface {
	Broadcast(event SSEEvent)
	Subscribe(clientID string) <-chan SSEEvent
	Unsubscribe(clientID string)
}

SSEManager interface for Server-Sent Events

type ServiceDependencies2

type ServiceDependencies2 interface {
	// WorkflowControl returns a typed workflow controller if available.
	WorkflowControl() workflowctl.WorkflowControl

	// SSEManager returns the server-sent-event manager when supported.
	SSEManager() SSEManager

	// Database returns the shared GORM handle for the current runtime when available.
	Database() *gorm.DB
	// contains filtered or unexported methods
}

ServiceDependencies2 defines the typed dependencies exposed to management services and ops that require access to shared runtime collaborators.

type ServiceDepsBuilder

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

ServiceDepsBuilder constructs ServiceDependencies2 instances via a fluent API.

func NewServiceDepsBuilder

func NewServiceDepsBuilder() *ServiceDepsBuilder

NewServiceDepsBuilder returns a new builder for ServiceDependencies2 implementations.

func (*ServiceDepsBuilder) Build

Build materializes the immutable ServiceDependencies2 instance.

func (*ServiceDepsBuilder) WithDatabase

func (b *ServiceDepsBuilder) WithDatabase(db *gorm.DB) *ServiceDepsBuilder

WithDatabase configures the shared database handle. Passing nil leaves the dependency unset.

func (*ServiceDepsBuilder) WithSSEManager

func (b *ServiceDepsBuilder) WithSSEManager(mgr SSEManager) *ServiceDepsBuilder

WithSSEManager configures the SSE manager dependency.

func (*ServiceDepsBuilder) WithWorkflowControl

WithWorkflowControl configures the workflow controller dependency.

type Step

type Step interface {
	// contains filtered or unexported methods
}

Step is an internal interface used by the builder.

func NewNoTaskStep

func NewNoTaskStep[In any, Out any]() Step

func NewStep

func NewStep[In any, Out any](fn func(ctx context.Context, in In) (Out, error)) Step

NewStep constructs a step with signature func(ctx context.Context, in In) (Out, error).

func NewStepWithDeps

func NewStepWithDeps[In any, Out any](fn ActivityHandlerV2[In, Out]) Step

NewStepWithDeps constructs a step with signature func(deps OpDependencies, ctx context.Context, in In) (Out, error).

func StepDisallow

func StepDisallow(step Step) Step

StepDisallow marks a step as disallowed for direct task exposure.

type TaskBasedJobTool

type TaskBasedJobTool struct {
	TaskContext jobworkflow.TaskContext
}

func (*TaskBasedJobTool) AwaitJobs

func (j *TaskBasedJobTool) AwaitJobs(jobIds ...string) error

func (*TaskBasedJobTool) GetJobKey

func (j *TaskBasedJobTool) GetJobKey() jobdb.JobKey

func (*TaskBasedJobTool) SubmitJob added in v0.0.42

func (j *TaskBasedJobTool) SubmitJob(ctx context.Context, job jobdb.SubmitJob) (jobdb.JobKey, error)

func (*TaskBasedJobTool) TaskOrdinal added in v0.0.56

func (j *TaskBasedJobTool) TaskOrdinal() int64

type TaskStep

type TaskStep struct {
	Name           string
	InputType      reflect.Type
	OutputType     reflect.Type
	DisallowAsTask bool
	NextStepTask   string
	Invoke         func(deps OpDependencies, ctx context.Context, resolvedInput map[string]interface{}) (map[string]interface{}, error)
}

TaskStep describes an executable step within an op.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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