task

package
v0.0.0-...-b988991 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package task 任务对象

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 任务执行的结果

Jump to

Keyboard shortcuts

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