pipeline

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package pipeline provides the pipeline engine for revoco.

Pipelines define workflows using GitHub Actions-style YAML with jobs containing sequential steps. Jobs can run in parallel based on their dependencies (needs).

Example pipeline:

name: backup-photos
on:
  schedule: "0 2 * * *"
jobs:
  fetch:
    steps:
      - uses: google-photos
        with:
          album: "Camera Roll"
  process:
    needs: [fetch]
    steps:
      - uses: heic-to-jpg
        selector:
          extensions: [".heic"]
  export:
    needs: [process]
    steps:
      - uses: local-folder
        with:
          path: ~/Pictures/Backup

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DAGScheduler

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

DAGScheduler manages job execution based on dependencies.

func NewDAGScheduler

func NewDAGScheduler(pipeline *Pipeline, run *PipelineRun) *DAGScheduler

NewDAGScheduler creates a new scheduler for the pipeline.

func (*DAGScheduler) Errors

func (s *DAGScheduler) Errors() <-chan error

Done returns a channel for errors.

func (*DAGScheduler) HasFailures

func (s *DAGScheduler) HasFailures() bool

HasFailures returns true if any jobs failed.

func (*DAGScheduler) JobCompleted

func (s *DAGScheduler) JobCompleted(jobID string, success bool, err error)

JobCompleted marks a job as completed.

func (*DAGScheduler) Ready

func (s *DAGScheduler) Ready() <-chan string

Ready returns a channel that emits job IDs when they're ready to run.

func (*DAGScheduler) Start

func (s *DAGScheduler) Start(ctx context.Context)

Start begins the scheduling loop.

func (*DAGScheduler) Stop

func (s *DAGScheduler) Stop()

Stop stops the scheduler.

type DefaultExecutor

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

DefaultExecutor is the standard pipeline executor implementation.

func NewExecutor

func NewExecutor(resolver PluginResolver, opts ...ExecutorOption) *DefaultExecutor

NewExecutor creates a new pipeline executor.

func (*DefaultExecutor) Cancel

func (e *DefaultExecutor) Cancel(runID string) error

Cancel stops a running pipeline.

func (*DefaultExecutor) Execute

func (e *DefaultExecutor) Execute(ctx context.Context, pipeline *Pipeline, progress ProgressCallback) (*PipelineRun, error)

Execute runs a pipeline and returns when complete.

func (*DefaultExecutor) Status

func (e *DefaultExecutor) Status(runID string) (*PipelineRun, error)

Status returns the current status of a pipeline run.

type DependencyGraph

type DependencyGraph struct {
	// Forward edges: job -> jobs that depend on it
	Dependents map[string][]string

	// Backward edges: job -> jobs it depends on
	Dependencies map[string][]string

	// Topological order
	Order []string
}

DependencyGraph represents the job dependency graph.

func BuildDependencyGraph

func BuildDependencyGraph(pipeline *Pipeline) (*DependencyGraph, error)

BuildDependencyGraph constructs a dependency graph from a pipeline.

func (*DependencyGraph) CriticalPath

func (g *DependencyGraph) CriticalPath() []string

CriticalPath returns the longest path through the graph.

func (*DependencyGraph) Levels

func (g *DependencyGraph) Levels() [][]string

Levels returns jobs grouped by execution level. Level 0 = root jobs, Level 1 = jobs depending on Level 0, etc.

func (*DependencyGraph) ParallelGroups

func (g *DependencyGraph) ParallelGroups() [][]string

ParallelGroups returns groups of jobs that can run in parallel.

type Duration

type Duration time.Duration

Duration is a wrapper for time.Duration that supports YAML parsing.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the underlying time.Duration.

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler for Duration.

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler for Duration.

type Executor

type Executor interface {
	// Execute runs a pipeline and returns when complete.
	Execute(ctx context.Context, pipeline *Pipeline, progress ProgressCallback) (*PipelineRun, error)

	// Cancel stops a running pipeline.
	Cancel(runID string) error

	// Status returns the current status of a pipeline run.
	Status(runID string) (*PipelineRun, error)
}

Executor runs pipelines.

type ExecutorOption

type ExecutorOption func(*DefaultExecutor)

ExecutorOption configures the executor.

func WithJobTimeout

func WithJobTimeout(d time.Duration) ExecutorOption

WithJobTimeout sets the default job timeout.

func WithMaxParallel

func WithMaxParallel(n int) ExecutorOption

WithMaxParallel sets the maximum number of parallel jobs.

func WithStepTimeout

func WithStepTimeout(d time.Duration) ExecutorOption

WithStepTimeout sets the default step timeout.

type Job

type Job struct {
	// Display name
	Name string `yaml:"name,omitempty" json:"name,omitempty"`

	// Job dependencies (other job IDs that must complete first)
	Needs []string `yaml:"needs,omitempty" json:"needs,omitempty"`

	// Condition to run this job (Lua expression)
	If string `yaml:"if,omitempty" json:"if,omitempty"`

	// Environment variables for this job
	Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`

	// Steps to execute (in order)
	Steps []*Step `yaml:"steps" json:"steps"`

	// Timeout for the entire job
	Timeout Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`

	// Continue pipeline even if this job fails
	ContinueOnError bool `yaml:"continue-on-error,omitempty" json:"continue-on-error,omitempty"`

	// Runtime state (not serialized)
	ID string `yaml:"-" json:"-"` // Set during parsing
}

Job represents a unit of work in the pipeline. Jobs run in parallel unless they have dependencies.

func (*Job) Normalize

func (j *Job) Normalize()

Normalize fills in default values for a job.

func (*Job) Validate

func (j *Job) Validate() error

Validate checks if a job is valid.

type JobRun

type JobRun struct {
	// Identity
	ID        string    `json:"id"`
	JobID     string    `json:"job_id"`
	StartTime time.Time `json:"start_time,omitempty"`
	EndTime   time.Time `json:"end_time,omitempty"`

	// State
	State   JobState `json:"state"`
	Message string   `json:"message,omitempty"`

	// Step runs
	Steps []*StepRun `json:"steps"`

	// Items at job start and end
	InputItems  []*core.DataItem `json:"-"`
	OutputItems []*core.DataItem `json:"-"`
}

JobRun represents a single execution of a job.

type JobState

type JobState string

JobState represents the execution state of a job.

const (
	JobStatePending   JobState = "pending"
	JobStateQueued    JobState = "queued"
	JobStateRunning   JobState = "running"
	JobStateCompleted JobState = "completed"
	JobStateFailed    JobState = "failed"
	JobStateSkipped   JobState = "skipped"
	JobStateCancelled JobState = "cancelled"
)

type Pipeline

type Pipeline struct {
	// Identity
	Name        string `yaml:"name" json:"name"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	Version     string `yaml:"version,omitempty" json:"version,omitempty"`

	// Triggers
	On *Trigger `yaml:"on,omitempty" json:"on,omitempty"`

	// Environment variables available to all jobs
	Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`

	// Jobs to execute
	Jobs map[string]*Job `yaml:"jobs" json:"jobs"`

	// Source file path (set during loading)
	SourcePath string `yaml:"-" json:"-"`
}

Pipeline represents a complete workflow definition.

func DiscoverPipelines

func DiscoverPipelines(dir string) ([]*Pipeline, error)

DiscoverPipelines finds all pipeline files in a directory.

func Parse

func Parse(data []byte) (*Pipeline, error)

Parse parses a pipeline from YAML bytes.

func ParseFile

func ParseFile(path string) (*Pipeline, error)

ParseFile loads a pipeline from a YAML file.

func (*Pipeline) Clone

func (p *Pipeline) Clone() *Pipeline

Clone creates a deep copy of the pipeline.

func (*Pipeline) Dependents

func (p *Pipeline) Dependents(jobID string) []string

Dependents returns jobs that depend on the given job.

func (*Pipeline) JobOrder

func (p *Pipeline) JobOrder() ([]string, error)

JobOrder returns jobs in topological order (dependencies first).

func (*Pipeline) Normalize

func (p *Pipeline) Normalize()

Normalize fills in default values and generates IDs.

func (*Pipeline) RootJobs

func (p *Pipeline) RootJobs() []string

RootJobs returns jobs with no dependencies.

func (*Pipeline) Validate

func (p *Pipeline) Validate() error

Validate checks if the pipeline is valid.

type PipelineProgress

type PipelineProgress struct {
	Run      *PipelineRun
	Job      *JobRun
	Step     *StepRun
	Event    ProgressEvent
	Progress float64 // 0.0 to 1.0
	Message  string
}

PipelineProgress reports pipeline execution progress.

type PipelineRun

type PipelineRun struct {
	// Identity
	ID         string    `json:"id"`
	PipelineID string    `json:"pipeline_id"`
	StartTime  time.Time `json:"start_time"`
	EndTime    time.Time `json:"end_time,omitempty"`

	// State
	State   PipelineState `json:"state"`
	Message string        `json:"message,omitempty"`

	// Job runs
	Jobs map[string]*JobRun `json:"jobs"`

	// Data passed between jobs
	Items []*core.DataItem `json:"-"`
	// contains filtered or unexported fields
}

PipelineRun represents a single execution of a pipeline.

func NewPipelineRun

func NewPipelineRun(id string, pipeline *Pipeline) *PipelineRun

NewPipelineRun creates a new pipeline run.

func (*PipelineRun) Cancel

func (r *PipelineRun) Cancel()

Cancel cancels the pipeline run.

func (*PipelineRun) CompletedJobs

func (r *PipelineRun) CompletedJobs() int

CompletedJobs returns the number of completed jobs.

func (*PipelineRun) Context

func (r *PipelineRun) Context() context.Context

Context returns the run's context.

func (*PipelineRun) Duration

func (r *PipelineRun) Duration() time.Duration

Duration returns how long the run took.

func (*PipelineRun) IsComplete

func (r *PipelineRun) IsComplete() bool

IsComplete returns true if the run has finished.

func (*PipelineRun) Progress

func (r *PipelineRun) Progress() float64

Progress returns the overall pipeline progress (0.0 to 1.0).

func (*PipelineRun) TotalJobs

func (r *PipelineRun) TotalJobs() int

TotalJobs returns the total number of jobs.

type PipelineState

type PipelineState string

PipelineState represents the execution state of a pipeline.

const (
	PipelineStatePending   PipelineState = "pending"
	PipelineStateRunning   PipelineState = "running"
	PipelineStateCompleted PipelineState = "completed"
	PipelineStateFailed    PipelineState = "failed"
	PipelineStateCancelled PipelineState = "cancelled"
)

type PluginResolver

type PluginResolver interface {
	// ResolveConnector finds a connector plugin.
	ResolveConnector(id string) (plugins.ConnectorPlugin, error)

	// ResolveProcessor finds a processor plugin.
	ResolveProcessor(id string) (plugins.ProcessorPlugin, error)

	// ResolveOutput finds an output plugin.
	ResolveOutput(id string) (plugins.OutputPlugin, error)
}

PluginResolver looks up plugins by ID.

type ProgressCallback

type ProgressCallback func(progress PipelineProgress)

ProgressCallback is called when pipeline execution progress changes.

type ProgressEvent

type ProgressEvent string

ProgressEvent indicates what kind of progress update occurred.

const (
	EventPipelineStarted   ProgressEvent = "pipeline_started"
	EventPipelineCompleted ProgressEvent = "pipeline_completed"
	EventPipelineFailed    ProgressEvent = "pipeline_failed"
	EventJobStarted        ProgressEvent = "job_started"
	EventJobCompleted      ProgressEvent = "job_completed"
	EventJobFailed         ProgressEvent = "job_failed"
	EventJobSkipped        ProgressEvent = "job_skipped"
	EventStepStarted       ProgressEvent = "step_started"
	EventStepCompleted     ProgressEvent = "step_completed"
	EventStepFailed        ProgressEvent = "step_failed"
	EventStepProgress      ProgressEvent = "step_progress"
)

type Step

type Step struct {
	// Step identifier (optional, auto-generated if not provided)
	ID string `yaml:"id,omitempty" json:"id,omitempty"`

	// Display name
	Name string `yaml:"name,omitempty" json:"name,omitempty"`

	// Plugin to use (e.g., "google-photos", "heic-to-jpg")
	Uses string `yaml:"uses" json:"uses"`

	// Plugin configuration
	With map[string]any `yaml:"with,omitempty" json:"with,omitempty"`

	// Item selector (for processors and outputs)
	Selector *plugins.Selector `yaml:"selector,omitempty" json:"selector,omitempty"`

	// Condition to run this step (Lua expression)
	If string `yaml:"if,omitempty" json:"if,omitempty"`

	// Timeout for this step
	Timeout Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`

	// Continue job even if this step fails
	ContinueOnError bool `yaml:"continue-on-error,omitempty" json:"continue-on-error,omitempty"`

	// Environment variables for this step
	Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
}

Step represents a single action within a job.

func (*Step) Normalize

func (s *Step) Normalize(index int)

Normalize fills in default values for a step.

func (*Step) Validate

func (s *Step) Validate() error

Validate checks if a step is valid.

type StepRun

type StepRun struct {
	// Identity
	ID        string    `json:"id"`
	StepID    string    `json:"step_id"`
	StepIndex int       `json:"step_index"`
	StartTime time.Time `json:"start_time,omitempty"`
	EndTime   time.Time `json:"end_time,omitempty"`

	// State
	State   StepState `json:"state"`
	Message string    `json:"message,omitempty"`

	// Progress
	ItemsProcessed int `json:"items_processed"`
	ItemsTotal     int `json:"items_total"`

	// Items at step start and end
	InputItems  []*core.DataItem `json:"-"`
	OutputItems []*core.DataItem `json:"-"`
}

StepRun represents a single execution of a step.

type StepState

type StepState string

StepState represents the execution state of a step.

const (
	StepStatePending   StepState = "pending"
	StepStateRunning   StepState = "running"
	StepStateCompleted StepState = "completed"
	StepStateFailed    StepState = "failed"
	StepStateSkipped   StepState = "skipped"
)

type Trigger

type Trigger struct {
	// Cron schedule (e.g., "0 2 * * *" for 2 AM daily)
	Schedule string `yaml:"schedule,omitempty" json:"schedule,omitempty"`

	// Run on specific events
	Events []string `yaml:"events,omitempty" json:"events,omitempty"`

	// Manual trigger only
	Manual bool `yaml:"manual,omitempty" json:"manual,omitempty"`
}

Trigger defines when a pipeline should run.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a pipeline validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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