core

package
v0.0.5-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultUnit

type DefaultUnit struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

默认的Unit实现

type ExecutionState

type ExecutionState interface {
	Save(state PipelineState) error
	Load() (PipelineState, error)
}

type IJob

type IJob[T any] interface {
	ID() string        // 任务唯一标识
	Status() JobStatus // 任务的整体状态
	GetPolicy() IJobPolicy
	Execute(ctx context.Context, input any, current *Unit) (T, error) //
}

IJob Job接口:每个单元固定绑定一个Job,实现输入->输出的逻辑

type IJobPolicy

type IJobPolicy interface {
	RetryCount() int           // 重试次数
	MaxRetries() int           // 最大重试次数
	RetryDelay() time.Duration // 每次重试之间的延迟
}

type IStage

type IStage[T any] interface {
	Name() string        // 阶段名称
	Status() StageStatus // 阶段状态
	DependsOn() []string // 依赖的阶段NAME(空表示第一个阶段)
	// contains filtered or unexported methods
}

type Job

type Job struct {
	Name    string // 任务名称
	Results any    // 存储阶段产物,key 为阶段名称

	Output       any                                                          // 输出可以是任意类型的数据
	Input        any                                                          // 输入也可以是任意类型的数据
	Policy       IJobPolicy                                                   //
	Dependencies []*IJob[any]                                                 // 该任务依赖的其他任务, 用于构建依赖关系
	Executor     func(ctx context.Context, i any, current *Unit) (any, error) // 执行器
	// contains filtered or unexported fields
}

func NewJob

func NewJob(name string) *Job

func (*Job) Execute

func (j *Job) Execute(ctx context.Context, input any, current *Unit) (any, error)

func (*Job) GetPolicy

func (j *Job) GetPolicy() IJobPolicy

func (*Job) ID

func (j *Job) ID() string

func (*Job) Status

func (j *Job) Status() JobStatus

type JobPolicy

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

func NewPolicy

func NewPolicy(
	maxRetries int,
	retryDelay time.Duration,
) *JobPolicy

func (*JobPolicy) MaxRetries

func (j *JobPolicy) MaxRetries() int

func (*JobPolicy) ReachMaxRetries

func (j *JobPolicy) ReachMaxRetries() bool

func (*JobPolicy) Retry

func (j *JobPolicy) Retry()

func (*JobPolicy) RetryCount

func (j *JobPolicy) RetryCount() int

func (*JobPolicy) RetryDelay

func (j *JobPolicy) RetryDelay() time.Duration

type JobStatus

type JobStatus string
const (
	TaskPending   JobStatus = "PENDING"
	TaskRunning   JobStatus = "RUNNING"
	TaskCompleted JobStatus = "COMPLETED"
	TaskFailed    JobStatus = "FAILED"
)

type JobUnit

type JobUnit struct {
	UnitId string    // Unit id
	Job    IJob[any] // 绑定的任务
}

func NewJobUnit

func NewJobUnit(job IJob[any]) *JobUnit

func (*JobUnit) ID

func (u *JobUnit) ID() string

func (*JobUnit) Run

func (u *JobUnit) Run(ctx context.Context, input any, current *Unit) (any, error)

Run Run执行自身绑定的Job逻辑

type Line added in v0.0.5

type Line struct {
	From string
	To   string
}

type Pipeline

type Pipeline struct {
	ID string

	Status     string // "pending", "running", "completed", "failed", "terminal", "retry", "resume","paused"
	StartTime  time.Time
	EndTime    time.Time
	StateStore ExecutionState

	Results map[string]any
	// contains filtered or unexported fields
}

Pipeline 是整个 CI/CD 流水线,包含多个阶段

func NewPipeline

func NewPipeline(StateStore ExecutionState, stages ...*Stage) *Pipeline

func (*Pipeline) ApplyState

func (p *Pipeline) ApplyState(state PipelineState)

func (*Pipeline) LoadState

func (p *Pipeline) LoadState() error

LoadState 在Resume或启动时从store加载状态

func (*Pipeline) Pause

func (p *Pipeline) Pause()

Pause For controlling pipeline execution

func (*Pipeline) Resume

func (p *Pipeline) Resume()

func (*Pipeline) Run

func (p *Pipeline) Run(ctx context.Context, initialInput any) (any, error)

func (*Pipeline) RunWithCallback added in v0.0.5

func (p *Pipeline) RunWithCallback(ctx context.Context, initialInput any, callback StageCallback) (any, error)

func (*Pipeline) SaveState

func (p *Pipeline) SaveState()

SaveState 在合适时机调用saveState

func (*Pipeline) Stop

func (p *Pipeline) Stop()

type PipelineState

type PipelineState struct {
	CurrentStageIndex int
	// 如果Stage内部有多个Unit并行或串行执行的上下文,也需要记录当前Unit的进度
	CurrentUnitIndex int
	Status           string
	// 可以存储上一阶段的输出数据,用于从中间点恢复
	LastOutput any
}

type Stage

type Stage struct {
	Name      string `json:"name"`       // 阶段名称
	DependsOn string `json:"depends_on"` // 依赖的阶段NAME(空表示第一个阶段)

	Status StageStatus `json:"status"` // 阶段状态
	// contains filtered or unexported fields
}

func NewStage

func NewStage(name string, units []Unit) *Stage

func (*Stage) Run

func (s *Stage) Run(ctx context.Context, input any) (any, error)

type StageCallback added in v0.0.5

type StageCallback func(stageName string, status StageStatus, self *Pipeline) bool

type StageStatus

type StageStatus string
const (
	StagePending       StageStatus = "PENDING"
	StageRunning       StageStatus = "RUNNING"
	StageCompleted     StageStatus = "COMPLETED"
	StageFailed        StageStatus = "FAILED"
	StageNeedTerminate StageStatus = "BREAK"
)

type StoryBoard added in v0.0.5

type StoryBoard struct {
	Stages []*Stage //这里不是真正的Stage , 需要套一层UI-Data ,StageVo -》 Stage
	Lines  []*Line
}

故事版跟Pipeline的相似度处: 1. 都有Stage[] 2. 都有Stage关系 从StoryBoard创建Pipeline,只要有连线,校验通过

func (*StoryBoard) Build added in v0.0.5

func (u *StoryBoard) Build() (p *Pipeline, e error)

type Unit

type Unit interface {
	ID() string                                                     // Unit的ID,每次实例化可能不一样
	Run(ctx context.Context, input any, current *Unit) (any, error) // 执行单元的主要逻辑,会产出结果输出
}

Unit 表示具体的单元,由模板实例化而来。 一个Unit有输入输出的Channel描述、有执行Job的逻辑等

type UnitOutput

type UnitOutput struct {
	ID     string `json:"id"`
	Output any    `json:"output"`
}

type UnitRegistry

type UnitRegistry interface {
	Name() string         // Unit的名称
	Order() int           // 执行顺序
	TemplateName() string // 对应的模板名称
	SetInput(any) error   // 设置输入数据
	GetOutput() any       // 获取输出数据
}

type UnitTemplate

type UnitTemplate interface {
	Name() string
	Description() string
	// Instantiate 由Storyboard在构建Stage时调用,用于根据模板创建对应的Unit实例(单元)
	Instantiate() Unit
}

UnitTemplate 是零件模板接口,通过它可以实例化出对应的Unit。 不同的UnitTemplate可以定义不同的处理逻辑、输入输出类型等。

Jump to

Keyboard shortcuts

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