model

package
v0.5.7-rc2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2018 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusNotStarted indicates that the FlowInstance has not started
	FlowStatusNotStarted FlowStatus = 0

	// StatusActive indicates that the FlowInstance is active
	FlowStatusActive FlowStatus = 100

	// StatusCompleted indicates that the FlowInstance has been completed
	FlowStatusCompleted FlowStatus = 500

	// StatusCancelled indicates that the FlowInstance has been cancelled
	FlowStatusCancelled FlowStatus = 600

	// StatusFailed indicates that the FlowInstance has failed
	FlowStatusFailed FlowStatus = 700

	// TaskStatusNotStarted indicates that the Task has not been started
	TaskStatusNotStarted TaskStatus = 0

	// TaskStatusEntered indicates that the Task has been entered
	TaskStatusEntered TaskStatus = 10

	// TaskStatusReady indicates that the Task is ready
	TaskStatusReady TaskStatus = 20

	// TaskStatusWaiting indicates that the Task is waiting
	TaskStatusWaiting TaskStatus = 30

	// TaskStatusDone indicates that the Task is done
	TaskStatusDone TaskStatus = 40

	// TaskStatusSkipped indicates that the Task was skipped
	TaskStatusSkipped TaskStatus = 50

	// TaskStatusFailed indicates that the Task failed
	TaskStatusFailed TaskStatus = 100

	// LinkStatusFalse indicates that the Link evaluated to false
	LinkStatusFalse LinkStatus = 1

	// LinkStatusTrue indicates that the Link evaluated to true
	LinkStatusTrue LinkStatus = 2

	// LinkStatusSkipped indicates that the Link has been skipped
	LinkStatusSkipped LinkStatus = 3
)

Variables

This section is empty.

Functions

func Register

func Register(flowModel *FlowModel)

Register registers the specified flow model

func RegisterDefault added in v0.5.2

func RegisterDefault(flowModel *FlowModel)

Register registers the specified flow model

Types

type EnterResult added in v0.5.2

type EnterResult int
const (
	ENTER_NOTREADY EnterResult = iota
	ENTER_EVAL
	ENTER_SKIP
)

type EvalResult

type EvalResult int
const (
	EVAL_FAIL EvalResult = iota
	EVAL_DONE
	EVAL_REPEAT
	EVAL_WAIT
	EVAL_SKIP
)

type FlowBehavior

type FlowBehavior interface {

	// Start the flow instance.  Returning true indicates that the
	// flow can start and enter the specified tasks.
	// Return false indicates that the flow could not be started
	// at this time.
	Start(context FlowContext) (started bool, taskEntries []*TaskEntry)

	// StartErrorHandler start the error handler for the flow.
	// Return the list of tasks to start
	StartErrorHandler(context FlowContext) (taskEntries []*TaskEntry)

	// Resume the flow instance.  Returning true indicates that the
	// flow can resume.  Return false indicates that the flow
	// could not be resumed at this time.
	Resume(context FlowContext) (resumed bool)

	// TasksDone is called when a terminal task is Done.
	TaskDone(context FlowContext) (flowDone bool)

	// Done is called when the flow is done.
	Done(context FlowContext)
}

FlowBehavior is the execution behavior of the Flow.

type FlowContext

type FlowContext interface {
	// FlowDefinition returns the Flow definition associated with this context
	FlowDefinition() *definition.Definition

	// TaskInstances get the task instances
	TaskInstances() []TaskInstance

	// Status gets the state of the Flow instance
	Status() FlowStatus
}

FlowContext is the execution context of the Flow when executing a Flow Behavior function

type FlowModel

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

FlowModel defines the execution Model for a Flow. It contains the execution behaviors for Flows and Tasks.

func Default added in v0.5.2

func Default() *FlowModel

func Get

func Get(id string) *FlowModel

Get gets specified FlowModel

func New

func New(name string) *FlowModel

New creates a new FlowModel from the specified Behaviors

func Registered

func Registered() []*FlowModel

Registered gets all the registered flow models

func (*FlowModel) GetDefaultTaskBehavior added in v0.5.2

func (fm *FlowModel) GetDefaultTaskBehavior() TaskBehavior

RegisterDefaultTaskBehavior registers the default TaskBehavior for the Model

func (*FlowModel) GetFlowBehavior

func (fm *FlowModel) GetFlowBehavior() FlowBehavior

GetFlowBehavior returns FlowBehavior of the FlowModel

func (*FlowModel) GetTaskBehavior

func (fm *FlowModel) GetTaskBehavior(id string) TaskBehavior

GetTaskBehavior returns TaskBehavior with the specified ID in he FlowModel

func (*FlowModel) IsValidTaskType added in v0.5.2

func (fm *FlowModel) IsValidTaskType(taskType string) bool

func (*FlowModel) Name

func (fm *FlowModel) Name() string

Name returns the name of the FlowModel

func (*FlowModel) RegisterDefaultTaskBehavior added in v0.5.2

func (fm *FlowModel) RegisterDefaultTaskBehavior(id string, taskBehavior TaskBehavior)

func (*FlowModel) RegisterFlowBehavior

func (fm *FlowModel) RegisterFlowBehavior(flowBehavior FlowBehavior)

RegisterFlowBehavior registers the specified FlowBehavior with the Model

func (*FlowModel) RegisterTaskBehavior

func (fm *FlowModel) RegisterTaskBehavior(id string, taskBehavior TaskBehavior)

RegisterTaskBehavior registers the specified TaskBehavior with the Model

type FlowStatus added in v0.5.2

type FlowStatus int

type LinkInstance added in v0.5.2

type LinkInstance interface {

	// Link returns the Link associated with this Link Instance
	Link() *definition.Link

	// Status gets the state of the Link instance
	Status() LinkStatus

	// SetStatus sets the state of the Link instance
	SetStatus(status LinkStatus)
}

LinkInstance is the instance of a link

type LinkStatus added in v0.5.2

type LinkStatus int

type TaskBehavior

type TaskBehavior interface {

	// Enter determines if a Task is ready to be evaluated, or needs to be
	// skipped
	Enter(context TaskContext) (enterResult EnterResult)

	// Eval is called when a Task is being evaluated.  Returning true indicates
	// that the task is done.  If err is set, it indicates that the
	// behavior intends for the flow ErrorHandler to handle the error
	Eval(context TaskContext) (evalResult EvalResult, err error)

	// PostEval is called when a task that is waiting needs to be notified.
	// If err is set, it indicates that the behavior intends for the
	// flow ErrorHandler to handle the error
	PostEval(context TaskContext) (evalResult EvalResult, err error)

	// Done is called when Eval or PostEval return a result of DONE, indicating
	// that the task is done.  This step is used to finalize the task and
	// determine the next set of tasks to be entered.
	Done(context TaskContext) (notifyFlow bool, taskEntries []*TaskEntry, err error)

	// Skip is called when Enter returns a result of SKIP, indicating
	// that the task should be skipped.  This step is used to skip the task and
	// determine the next set of tasks to be entered.
	Skip(context TaskContext) (notifyFlow bool, taskEntries []*TaskEntry)

	// Error is called when there is an issue executing Eval, it returns a boolean indicating
	// if it handled the error, otherwise the error is handled by the global error handler
	Error(context TaskContext, err error) (handled bool, taskEntries []*TaskEntry)
}

TaskBehavior is the execution behavior of a Task.

type TaskContext

type TaskContext interface {

	// Status gets the state of the Task instance
	Status() TaskStatus

	// SetStatus sets the state of the Task instance
	SetStatus(status TaskStatus)

	// Task returns the Task associated with this context
	Task() *definition.Task

	// GetFromLinkInstances returns the instances of predecessor Links of the current task.
	GetFromLinkInstances() []LinkInstance

	// GetToLinkInstances returns the instances of successor Links of the current task.
	GetToLinkInstances() []LinkInstance

	// EvalLink evaluates the specified link
	EvalLink(link *definition.Link) (bool, error)

	// EvalActivity evaluates the Activity associated with the Task
	EvalActivity() (done bool, err error)

	// PostActivity does post evaluation of the Activity associated with the Task
	PostEvalActivity() (done bool, err error)

	Resolve(toResolve string) (value interface{}, err error)

	AddWorkingData(attr *data.Attribute)

	UpdateWorkingData(key string, value interface{}) error

	GetWorkingData(key string) (*data.Attribute, bool)
}

TaskContext is the execution context of the Task when executing a Task Behavior function

type TaskEntry

type TaskEntry struct {
	Task      *definition.Task
	EnterCode int
}

TaskEntry is a struct used to specify what Task to enter and its corresponding enter code

type TaskInstance added in v0.5.2

type TaskInstance interface {

	// Task returns the Task associated with this Task Instance
	Task() *definition.Task

	// Status gets the state of the Task instance
	Status() TaskStatus
}

type TaskStatus added in v0.5.2

type TaskStatus int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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