task

package
Version: v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Step

type Step interface {
	// Step 名字
	Name() string
	// 执行
	Do(ctx context.Context, stepIndex int, taskObj Task) *StepResult
	// 回滚
	Cancel(ctx context.Context, stepIndex int, taskObj Task) error
}

Step 任务执行的步骤

type StepResult

type StepResult struct {
	StepName string
	Result   interface{}
	Err      error
}

StepResult 任务执行的结果

type Task

type Task interface {
	// Name 任务名
	Name() string
	// Run 执行任务
	Run() (*TaskResult, error)
	// Rollback 任务回滚
	Rollback()
	// 得到运行参数
	GetTaskArgs() interface{}
	//
	GetStepResult(stepIndex int) *StepResult
}

Task 任务对象,管理Step

func MakeTask

func MakeTask(ctx context.Context, name string, observer TaskObserver, taskArg interface{}, steps ...Step) (Task, error)

MakeTask 构造一个Task对象

type TaskEvent

type TaskEvent struct {
	Info string
}

TaskEvent 通知事件

type TaskObserver

type TaskObserver interface {
	OnNotify(*TaskEvent)
}

TaskObserver 观察对象

type TaskResult

type TaskResult struct {
	Result []*StepResult
}

TaskResult 任务执行的结果

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL