scheduler

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const CredentialScopeHeader = "X-Workflow-Credential-Scope"

Variables

This section is empty.

Functions

func NextAutomationOccurrence

func NextAutomationOccurrence(config AutomationScheduleConfig, after time.Time) (time.Time, error)

Types

type AutomationFrequency

type AutomationFrequency string
const (
	AutomationDaily    AutomationFrequency = "daily"
	AutomationWeekdays AutomationFrequency = "weekdays"
	AutomationWeekly   AutomationFrequency = "weekly"
	AutomationInterval AutomationFrequency = "interval"
)

type AutomationSchedule

type AutomationSchedule struct {
	Key          string                   `json:"key"`
	WorkflowID   string                   `json:"workflow_id"`
	WorkflowName string                   `json:"workflow_name"`
	VersionID    string                   `json:"version_id"`
	TriggerID    string                   `json:"trigger_id"`
	Fingerprint  string                   `json:"-"`
	Config       AutomationScheduleConfig `json:"schedule"`
	Enabled      bool                     `json:"enabled"`
	NextRunAt    time.Time                `json:"next_run_at"`
	LastRunAt    time.Time                `json:"last_run_at,omitempty"`
	LastRunID    string                   `json:"last_run_id,omitempty"`
	LastError    string                   `json:"last_error,omitempty"`
	ClaimToken   string                   `json:"-"`
	ClaimUntil   time.Time                `json:"-"`
}

type AutomationScheduleConfig

type AutomationScheduleConfig struct {
	Frequency       AutomationFrequency `json:"frequency"`
	Time            string              `json:"time,omitempty"`
	Weekdays        []int               `json:"weekdays,omitempty"`
	IntervalMinutes int                 `json:"interval_minutes,omitempty"`
	Timezone        string              `json:"timezone"`
}

func ParseAutomationSchedule

func ParseAutomationSchedule(trigger definition.Trigger) (AutomationScheduleConfig, error)

type AutomationStatus

type AutomationStatus struct {
	AutomationSchedule
	LastRunStatus wfruntime.Status `json:"last_run_status,omitempty"`
}

type AutomationStore

type AutomationStore interface {
	ReconcileSchedules(ctx context.Context, desired []AutomationSchedule) error
	ClaimDueSchedules(ctx context.Context, now time.Time, limit int, lease time.Duration) ([]AutomationSchedule, error)
	CompleteSchedule(ctx context.Context, key, claimToken, runID string, scheduledAt, nextRunAt time.Time) error
	FailSchedule(ctx context.Context, key, claimToken, message string, retryAt time.Time) error
	ListSchedules(ctx context.Context) ([]AutomationSchedule, error)
}

type DispatchMode

type DispatchMode string
const (
	DispatchLocalFirst  DispatchMode = "local_first"
	DispatchRemoteFirst DispatchMode = "remote_first"
	DispatchRemoteOnly  DispatchMode = "remote_only"
)

type GormAutomationStore

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

func NewGormAutomationStore deprecated

func NewGormAutomationStore(db *gorm.DB) (*GormAutomationStore, error)

NewGormAutomationStore constructs the legacy standalone automation adapter.

Deprecated: new applications should compose the complete adapter through persist/gormstore.New. This constructor remains available for compatibility.

func (*GormAutomationStore) ClaimDueSchedules

func (s *GormAutomationStore) ClaimDueSchedules(
	ctx context.Context,
	now time.Time,
	limit int,
	lease time.Duration,
) ([]AutomationSchedule, error)

func (*GormAutomationStore) CompleteSchedule

func (s *GormAutomationStore) CompleteSchedule(
	ctx context.Context,
	key, claimToken, runID string,
	scheduledAt, nextRunAt time.Time,
) error

func (*GormAutomationStore) FailSchedule

func (s *GormAutomationStore) FailSchedule(
	ctx context.Context,
	key, claimToken, message string,
	retryAt time.Time,
) error

func (*GormAutomationStore) ListSchedules

func (s *GormAutomationStore) ListSchedules(ctx context.Context) ([]AutomationSchedule, error)

func (*GormAutomationStore) ReconcileSchedules

func (s *GormAutomationStore) ReconcileSchedules(ctx context.Context, desired []AutomationSchedule) error

type HTTPHandler

type HTTPHandler struct {
	Service *Service
}

func NewHTTPHandler

func NewHTTPHandler(service *Service) *HTTPHandler

func (*HTTPHandler) Handler

func (h *HTTPHandler) Handler() http.Handler

type HybridDispatcher

type HybridDispatcher struct {
	LocalRegistry *executor.Registry
	Workers       WorkerRegistry
	HTTPClient    *RemoteHTTPClient
	Mode          DispatchMode
}

func NewHybridDispatcher

func NewHybridDispatcher(local *executor.Registry, workers WorkerRegistry, client *RemoteHTTPClient) *HybridDispatcher

func (*HybridDispatcher) Dispatch

type MemoryAutomationStore

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

MemoryAutomationStore provides the same scheduling contract as the durable store without persistence. It is suitable for tests and short-lived apps.

func NewMemoryAutomationStore

func NewMemoryAutomationStore() *MemoryAutomationStore

func (*MemoryAutomationStore) ClaimDueSchedules

func (s *MemoryAutomationStore) ClaimDueSchedules(
	_ context.Context,
	now time.Time,
	limit int,
	lease time.Duration,
) ([]AutomationSchedule, error)

func (*MemoryAutomationStore) CompleteSchedule

func (s *MemoryAutomationStore) CompleteSchedule(
	_ context.Context,
	key, claimToken, runID string,
	scheduledAt, nextRunAt time.Time,
) error

func (*MemoryAutomationStore) FailSchedule

func (s *MemoryAutomationStore) FailSchedule(
	_ context.Context,
	key, claimToken, message string,
	retryAt time.Time,
) error

func (*MemoryAutomationStore) ListSchedules

func (*MemoryAutomationStore) ReconcileSchedules

func (s *MemoryAutomationStore) ReconcileSchedules(_ context.Context, desired []AutomationSchedule) error

type MemoryWorkerRegistry

type MemoryWorkerRegistry struct {
	HeartbeatTTL time.Duration
	Now          func() time.Time
	// contains filtered or unexported fields
}

func NewMemoryWorkerRegistry

func NewMemoryWorkerRegistry() *MemoryWorkerRegistry

func (*MemoryWorkerRegistry) AcquireForTask

func (r *MemoryWorkerRegistry) AcquireForTask(_ context.Context, task executor.ExecuteTask) (*WorkerLease, error)

func (*MemoryWorkerRegistry) FindForTask

func (*MemoryWorkerRegistry) Heartbeat

func (r *MemoryWorkerRegistry) Heartbeat(_ context.Context, workerID string) error

func (*MemoryWorkerRegistry) List

func (*MemoryWorkerRegistry) Register

type Options

type Options struct {
	Compiler               planning.Compiler
	Store                  wfruntime.Store
	Definitions            definition.Repository
	Workspace              definition.WorkspaceRepository
	RunController          runner.RunController
	EnableEmbeddedWorker   bool
	EmbeddedWorker         *worker.Service
	WorkerRegistry         WorkerRegistry
	DispatchMode           DispatchMode
	ResultReporter         runner.ResultReporter
	HeartbeatReporter      runner.HeartbeatReporter
	Credentials            credential.Store
	DefaultCredentialScope string
	Automations            AutomationStore
}

type PublishedAPIContract

type PublishedAPIContract struct {
	WorkflowID   string                   `json:"workflow_id"`
	VersionID    string                   `json:"version_id"`
	Version      int                      `json:"version"`
	Name         string                   `json:"name"`
	Description  string                   `json:"description,omitempty"`
	Route        string                   `json:"route"`
	URL          string                   `json:"url,omitempty"`
	InvokeURL    string                   `json:"invoke_url,omitempty"`
	AsyncURL     string                   `json:"async_url,omitempty"`
	StreamURL    string                   `json:"stream_url_template,omitempty"`
	Method       string                   `json:"method"`
	InputMode    string                   `json:"input_mode"`
	ResponseMode string                   `json:"response_mode"`
	TimeoutMS    int64                    `json:"timeout"`
	Inputs       []PublishedAPIInputField `json:"inputs,omitempty"`
	Example      map[string]any           `json:"request_example,omitempty"`
}

type PublishedAPIInputField

type PublishedAPIInputField struct {
	Key         string                       `json:"key"`
	Label       map[string]string            `json:"label"`
	Description map[string]string            `json:"description,omitempty"`
	Kind        string                       `json:"kind"`
	Required    bool                         `json:"required,omitempty"`
	Default     any                          `json:"default,omitempty"`
	Options     []PublishedAPIInputOption    `json:"options,omitempty"`
	VisibleWhen *PublishedAPIInputVisibility `json:"visible_when,omitempty"`
	// contains filtered or unexported fields
}

type PublishedAPIInputOption

type PublishedAPIInputOption struct {
	Value string            `json:"value"`
	Label map[string]string `json:"label"`
}

type PublishedAPIInputVisibility

type PublishedAPIInputVisibility struct {
	Key       string `json:"key"`
	Equals    any    `json:"equals,omitempty"`
	NotEquals any    `json:"not_equals,omitempty"`
	// contains filtered or unexported fields
}

type RegistryHTTPHandler

type RegistryHTTPHandler struct {
	Workers WorkerRegistry
}

func NewRegistryHTTPHandler

func NewRegistryHTTPHandler(workers WorkerRegistry) *RegistryHTTPHandler

func (*RegistryHTTPHandler) Handler

func (h *RegistryHTTPHandler) Handler() http.Handler

type RemoteBoundExecutor

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

func (*RemoteBoundExecutor) Cancel

func (e *RemoteBoundExecutor) Cancel(ctx context.Context, task executor.ExecuteTask, externalTaskID string) error

func (*RemoteBoundExecutor) Execute

func (*RemoteBoundExecutor) Poll

func (*RemoteBoundExecutor) Type

func (e *RemoteBoundExecutor) Type() executor.Type

type RemoteHTTPClient

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

func NewRemoteHTTPClient

func NewRemoteHTTPClient(client *http.Client) *RemoteHTTPClient

func (*RemoteHTTPClient) Cancel

func (c *RemoteHTTPClient) Cancel(ctx context.Context, worker workerproto.WorkerDescriptor, task executor.ExecuteTask, externalTaskID string) error

func (*RemoteHTTPClient) Execute

func (*RemoteHTTPClient) Poll

type RunRequest

type RunRequest struct {
	Definition *definition.WorkflowDefinition `json:"definition,omitempty"`
	Version    *definition.WorkflowVersion    `json:"version,omitempty"`
	VersionID  string                         `json:"version_id,omitempty"`
	Run        *wfruntime.WorkflowRun         `json:"run,omitempty"`
}

type Service

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

Service is the orchestration entrypoint. It owns compilation, scheduling, runtime state, and optionally an embedded worker for single-binary deployments.

func NewService

func NewService(opts Options) (*Service, error)

func (*Service) AutomationError

func (s *Service) AutomationError() string

func (*Service) CancelRun

func (s *Service) CancelRun(ctx context.Context, runID string) (*wfruntime.WorkflowRun, error)

func (*Service) CreateVersion

func (s *Service) CreateVersion(ctx context.Context, workflowID string, workflowDefinition *definition.WorkflowDefinition) (*definition.WorkflowVersion, error)

func (*Service) CredentialStore

func (s *Service) CredentialStore() credential.Store

func (*Service) DefaultCredentialScope

func (s *Service) DefaultCredentialScope() string

func (*Service) DefinitionRepository

func (s *Service) DefinitionRepository() definition.Repository

func (*Service) EmbeddedWorker

func (s *Service) EmbeddedWorker() *worker.Service

func (*Service) GetActiveVersion

func (s *Service) GetActiveVersion(ctx context.Context, workflowID string) (*definition.WorkflowVersion, error)

func (*Service) GetVersion

func (s *Service) GetVersion(ctx context.Context, versionID string) (*definition.WorkflowVersion, error)

func (*Service) GetWorkflow

func (s *Service) GetWorkflow(ctx context.Context, workflowID string) (*definition.Workflow, error)

func (*Service) GetWorkspace

func (s *Service) GetWorkspace(ctx context.Context) (*definition.Workspace, error)

func (*Service) Handler

func (s *Service) Handler() http.Handler

func (*Service) ListAutomations

func (s *Service) ListAutomations(ctx context.Context) ([]AutomationStatus, error)

func (*Service) ListRuns

func (s *Service) ListRuns(ctx context.Context) ([]*wfruntime.WorkflowRun, error)

func (*Service) ListVersions

func (s *Service) ListVersions(ctx context.Context, workflowID string) ([]*definition.WorkflowVersion, error)

func (*Service) ListWorkers

func (s *Service) ListWorkers(ctx context.Context) ([]workerproto.WorkerDescriptor, error)

func (*Service) ListWorkflows

func (s *Service) ListWorkflows(ctx context.Context) ([]*definition.Workflow, error)

func (*Service) LoadRun

func (s *Service) LoadRun(ctx context.Context, runID string) (*wfruntime.WorkflowRun, error)

func (*Service) PauseRun

func (s *Service) PauseRun(ctx context.Context, runID string) (*wfruntime.WorkflowRun, error)

func (*Service) PublishVersion

func (s *Service) PublishVersion(ctx context.Context, versionID string) (*definition.WorkflowVersion, error)

func (*Service) ResumeRun

func (s *Service) ResumeRun(ctx context.Context, runID string) (*wfruntime.WorkflowRun, error)

func (*Service) RunController

func (s *Service) RunController() runner.RunController

func (*Service) RunDefinition

func (*Service) RunDueAutomations

func (s *Service) RunDueAutomations(ctx context.Context, now time.Time) error

func (*Service) RunEvents

func (s *Service) RunEvents(ctx context.Context, runID string) ([]wfruntime.RunEvent, error)

func (*Service) RunHTTPTrigger

func (s *Service) RunHTTPTrigger(ctx context.Context, workflowID string, request *http.Request) (*wfruntime.WorkflowRun, error)

func (*Service) RunPublishedVersion

func (s *Service) RunPublishedVersion(ctx context.Context, version *definition.WorkflowVersion, request *http.Request) (*wfruntime.WorkflowRun, error)

func (*Service) RunPublishedWorkflow

func (s *Service) RunPublishedWorkflow(ctx context.Context, workflowID string, request *http.Request) (*wfruntime.WorkflowRun, error)

func (*Service) RunSnapshots

func (s *Service) RunSnapshots(ctx context.Context, runID string) ([]*wfruntime.RunSnapshot, error)

func (*Service) RunVersion

func (*Service) RunVersionByID

func (s *Service) RunVersionByID(ctx context.Context, versionID string, run *wfruntime.WorkflowRun) (*wfruntime.WorkflowRun, error)

func (*Service) SaveVersion

func (s *Service) SaveVersion(ctx context.Context, version *definition.WorkflowVersion) error

func (*Service) SaveWorkflow

func (s *Service) SaveWorkflow(ctx context.Context, workflow *definition.Workflow) error

func (*Service) SaveWorkspace

func (s *Service) SaveWorkspace(ctx context.Context, workspace *definition.Workspace, expectedRevision uint64) (*definition.Workspace, error)

func (*Service) Shutdown

func (s *Service) Shutdown(ctx context.Context) error

func (*Service) StartAutomations

func (s *Service) StartAutomations(ctx context.Context, pollInterval time.Duration) error

func (*Service) StartDefinition

func (*Service) StartPublishedVersion

func (s *Service) StartPublishedVersion(ctx context.Context, version *definition.WorkflowVersion, request *http.Request) (*wfruntime.WorkflowRun, error)

StartPublishedVersion validates published input and starts the same immutable version used by synchronous published calls.

func (*Service) StartVersion

StartVersion compiles and persists a pending run before executing it in the background. The returned value is an immutable snapshot safe for immediate HTTP serialization while the scheduler owns the live run instance.

func (*Service) StartVersionByID

func (s *Service) StartVersionByID(ctx context.Context, versionID string, run *wfruntime.WorkflowRun) (*wfruntime.WorkflowRun, error)

func (*Service) Store

func (s *Service) Store() wfruntime.Store

func (*Service) SyncAutomations

func (s *Service) SyncAutomations(ctx context.Context, now time.Time) error

func (*Service) ValidateDefinition

func (s *Service) ValidateDefinition(ctx context.Context, def *definition.WorkflowDefinition) (*planning.ExecutionPlan, error)

ValidateDefinition wraps an ad-hoc definition into an ephemeral version so the compiler validates it using the exact same rules as runtime execution.

func (*Service) ValidateVersion

func (s *Service) ValidateVersion(ctx context.Context, version *definition.WorkflowVersion) (*planning.ExecutionPlan, error)

ValidateVersion compiles a version into an execution plan without starting a run. The control plane uses this path to expose a cheap "can this definition run" check to the editor.

func (*Service) WorkerRegistry

func (s *Service) WorkerRegistry() WorkerRegistry

type ValidateResponse

type ValidateResponse struct {
	OK   bool                    `json:"ok"`
	Plan *planning.ExecutionPlan `json:"plan,omitempty"`
}

type WorkerAllocator

type WorkerAllocator interface {
	AcquireForTask(ctx context.Context, task executor.ExecuteTask) (*WorkerLease, error)
}

type WorkerLease

type WorkerLease struct {
	Worker  *workerproto.WorkerDescriptor
	Release func()
}

type WorkerRegistry

type WorkerRegistry interface {
	Register(ctx context.Context, worker workerproto.WorkerDescriptor) error
	Heartbeat(ctx context.Context, workerID string) error
	FindForTask(ctx context.Context, task executor.ExecuteTask) (*workerproto.WorkerDescriptor, error)
	List(ctx context.Context) ([]workerproto.WorkerDescriptor, error)
}

Jump to

Keyboard shortcuts

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