run

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Patch change immediately, this will increase the burden of storage
	// the default behavior
	PersistPriorityImmediately = "Immediately"
	// Patch change when after execute each action("RunBefore", "Run" or "RunAfter")
	// this will be high performance, but here is a risk to lost trace when application crashed
	PersistPriorityAfterAction = "AfterAction"
)

Variables

View Source
var (
	EndLoop = errors.New("end loop")
)

Functions

func LoopDo

func LoopDo(ctx ExecuteContext, do func() error, ops ...LoopDoOptionOp) error

LoopDo help you to complete loop action,for example

LoopDo(ctx, func(){
    log.Println("check status")
})

Types

type Action

type Action interface {
	Name() string
	Run(ctx ExecuteContext, params interface{}) error
}

Action is the interface that user action must implement

type AfterAction

type AfterAction interface {
	RunAfter(ctx ExecuteContext, params interface{}) error
}

AfterAction run after run action

type BeforeAction

type BeforeAction interface {
	RunBefore(ctx ExecuteContext, params interface{}) error
}

BeforeAction run before run action

type DefExecuteContext

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

Default Executor context

func NewDefExecuteContext

func NewDefExecuteContext(
	ctx context.Context,
	op ShareDataOperator,
	trace func(msg string, opt ...TraceOp),
	dagVars utils.KeyValueGetter,
	varsIterator utils.KeyValueIterator,
) *DefExecuteContext

NewDefExecuteContext

func (*DefExecuteContext) Context

func (e *DefExecuteContext) Context() context.Context

Context

func (*DefExecuteContext) GetVar

func (e *DefExecuteContext) GetVar(varName string) (string, bool)

GetVar used to get key from ShareData

func (*DefExecuteContext) IterateVars

func (e *DefExecuteContext) IterateVars(iterateFunc utils.KeyValueIterateFunc)

IterateVars used to iterate ShareData

func (*DefExecuteContext) ShareData

func (e *DefExecuteContext) ShareData() ShareDataOperator

ShareData

func (*DefExecuteContext) Trace

func (e *DefExecuteContext) Trace(msg string, opt ...TraceOp)

Trace print msg to the TaskInstance.Traces.

func (*DefExecuteContext) Tracef

func (e *DefExecuteContext) Tracef(msg string, a ...interface{})

Tracef print msg to the TaskInstance.Traces. Arguments are handled in the manner of fmt.Printf. Opt can only be placed at the end of args. Tracef("{format_str}",{format_val},{opts}) e.g. Tracef("%d", 1, TraceOpPersistAfterAction) wrong case: Tracef("%d", TraceOpPersistAfterAction, 1)

func (*DefExecuteContext) WithValue

func (e *DefExecuteContext) WithValue(key, value interface{})

WithValue is wrapper of "context.WithValue"

type ExecuteContext

type ExecuteContext interface {
	Context() context.Context
	// WithValue can attach value to context,so can share data between action
	// however it is base on memory, it is possible to lose changes such as application crash
	WithValue(key, value interface{})
	ShareData() ShareDataOperator
	// Trace print msg to the TaskInstance.Traces.
	Trace(msg string, opt ...TraceOp)
	// Tracef print msg to the TaskInstance.Traces.
	// Arguments are handled in the manner of fmt.Printf.
	// Opt can only be placed at the end of args.
	// Tracef("{format_str}",{format_val},{opts})
	// e.g. Tracef("%d", 1, TraceOpPersistAfterAction)
	// wrong case: Tracef("%d", TraceOpPersistAfterAction, 1)
	Tracef(msg string, a ...interface{})
	GetVar(varName string) (string, bool)
	IterateVars(iterateFunc utils.KeyValueIterateFunc)
}

ExecuteContext is a context using by action

type LoopDoOption

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

LoopDoOption

type LoopDoOptionOp

type LoopDoOptionOp func(loop *LoopDoOption)

func LoopInterval

func LoopInterval(duration time.Duration) LoopDoOptionOp

LoopInterval indicate the interval of loop

type MockAction

type MockAction struct {
	mock.Mock
}

MockAction is an autogenerated mock type for the Action type

func (*MockAction) Name

func (_m *MockAction) Name() string

Name provides a mock function with given fields:

func (*MockAction) ParameterNew

func (_m *MockAction) ParameterNew() interface{}

ParameterNew provides a mock function with given fields:

func (*MockAction) RetryBefore

func (_m *MockAction) RetryBefore(ctx ExecuteContext, params interface{}) error

RetryBefore provides a mock function with given fields: ctx, params

func (*MockAction) Run

func (_m *MockAction) Run(ctx ExecuteContext, params interface{}) error

Run provides a mock function with given fields: ctx, params

func (*MockAction) RunAfter

func (_m *MockAction) RunAfter(ctx ExecuteContext, params interface{}) error

RunAfter provides a mock function with given fields: ctx, params

func (*MockAction) RunBefore

func (_m *MockAction) RunBefore(ctx ExecuteContext, params interface{}) error

RunBefore provides a mock function with given fields: ctx, params

type MockExecuteContext

type MockExecuteContext struct {
	mock.Mock
}

MockExecuteContext is an autogenerated mock type for the ExecuteContext type

func (*MockExecuteContext) Context

func (_m *MockExecuteContext) Context() context.Context

Context provides a mock function with given fields:

func (*MockExecuteContext) GetVar

func (_m *MockExecuteContext) GetVar(varName string) (string, bool)

GetVar provides a mock function with given fields: varName

func (*MockExecuteContext) IterateVars

func (_m *MockExecuteContext) IterateVars(iterateFunc utils.KeyValueIterateFunc)

IterateVars provides a mock function with given fields: iterateFunc

func (*MockExecuteContext) ShareData

func (_m *MockExecuteContext) ShareData() ShareDataOperator

ShareData provides a mock function with given fields:

func (*MockExecuteContext) Trace

func (_m *MockExecuteContext) Trace(msg string, opt ...TraceOp)

Trace provides a mock function with given fields: msg, opt

func (*MockExecuteContext) Tracef

func (_m *MockExecuteContext) Tracef(msg string, a ...interface{})

Tracef provides a mock function with given fields: msg, a

func (*MockExecuteContext) WithValue

func (_m *MockExecuteContext) WithValue(key interface{}, value interface{})

WithValue provides a mock function with given fields: key, value

type ParameterAction

type ParameterAction interface {
	ParameterNew() interface{}
}

ParameterAction means action has parameter

type PersistPriority

type PersistPriority string

PersistPriority

type RetryBeforeAction

type RetryBeforeAction interface {
	RetryBefore(ctx ExecuteContext, params interface{}) error
}

RetryBeforeAction execute before retry

type RunFunc

type RunFunc func(ctx ExecuteContext, params interface{}) error

RunFunc is task concrete action

type ShareDataOperator

type ShareDataOperator interface {
	Get(key string) (string, bool)
	Set(key string, val string)
}

ShareDataOperator used to operate share data

type TraceOp

type TraceOp func(opt *TraceOption)
var (
	// TraceOpPersistAfterAction
	// Patch change when after execute each action("RunBefore", "Run" or "RunAfter")
	// this will be high performance, but here is a risk to lost trace when application crashed
	TraceOpPersistAfterAction TraceOp = func(opt *TraceOption) {
		opt.Priority = PersistPriorityAfterAction
	}
)

type TraceOption

type TraceOption struct {
	Priority PersistPriority
}

TraceOption

func NewTraceOption

func NewTraceOption(ops ...TraceOp) *TraceOption

NewTraceOption

Jump to

Keyboard shortcuts

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