Documentation ¶
Index ¶
- Variables
- func NewUndefinedExecutorError(executorType ExecutorType) error
- func WrapWithTerminatedError(err error, event Event) error
- type DependenciesSnapshot
- type Environment
- type Event
- type Executor
- type ExecutorFunc
- type ExecutorRegistrar
- type ExecutorType
- type Params
- type Pipeline
- func (p *Pipeline) ID() string
- func (p *Pipeline) MustStart(ctx context.Context) <-chan Step
- func (p *Pipeline) OwnerID() string
- func (p *Pipeline) ShouldBeStarted() error
- func (p *Pipeline) SpecificationID() string
- func (p *Pipeline) Start(ctx context.Context) (<-chan Step, error)
- func (p *Pipeline) Started() bool
- func (p *Pipeline) WorkingScenarios() []specification.Scenario
- type Result
- type ScenarioSyncGroup
- type Step
- func NewScenarioStep(slug specification.Slug, event Event) Step
- func NewScenarioStepWithErr(err error, slug specification.Slug, event Event) Step
- func NewThesisStep(slug specification.Slug, pt ExecutorType, event Event) Step
- func NewThesisStepWithErr(err error, slug specification.Slug, pt ExecutorType, event Event) Step
- type TerminatedError
- type UndefinedExecutorError
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyStarted = errors.New("pipeline already started") ErrNotStarted = errors.New("pipeline not started") )
Functions ¶
func NewUndefinedExecutorError ¶
func NewUndefinedExecutorError(executorType ExecutorType) error
func WrapWithTerminatedError ¶
Types ¶
type DependenciesSnapshot ¶
type DependenciesSnapshot map[specification.Slug][]specification.Slug
func (DependenciesSnapshot) Equal ¶
func (s DependenciesSnapshot) Equal(other DependenciesSnapshot) bool
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
func NewEnvironment ¶
func NewEnvironment(size int) *Environment
func (*Environment) Load ¶
func (c *Environment) Load(key string) (interface{}, bool)
func (*Environment) Store ¶
func (c *Environment) Store(key string, value interface{})
type Executor ¶
type Executor interface { Execute( ctx context.Context, env *Environment, thesis specification.Thesis, ) Result }
Executor executes the specified action using the passed thesis.
Pipeline determines the progress of the specification pipeline, it runs each specification.Scenario that needs to be executed. To perform the scenario, you need to run each specification.Thesis and get the Result of executing this thesis. But Pipeline does not know how to execute the thesis, so it delegates this task to the Executor.
The Executor can use one of these functions to return the Result: Pass, Fail, Crash, Cancel.
func CancelingExecutor ¶
func CancelingExecutor() Executor
CancelingExecutor is a shortcut for create naive implementation of the Executor that constantly returns the canceled Result with "expected canceling" error. If the context is done returns the canceled Result with a context error. Does nothing else.
It's good to use for testing and mocking.
func CrashingExecutor ¶
func CrashingExecutor() Executor
CrashingExecutor is a shortcut for create naive implementation of the Executor that constantly returns the crashed Result with "expected crashing" error. If the context is done returns the canceled Result with a context error. Does nothing else.
It's good to use for testing and mocking.
func FailingExecutor ¶
func FailingExecutor() Executor
FailingExecutor is a shortcut for create naive implementation of the Executor that constantly returns the failed Result with "expected failing" error. If the context is done returns the canceled Result with a context error. Does nothing else.
It's good to use for testing and mocking.
func PassingExecutor ¶
func PassingExecutor() Executor
PassingExecutor is a shortcut for create naive implementation of the Executor that constantly returns the passed Result. If the context is done returns the canceled Result with a context error. Does nothing else.
It's good to use for testing and mocking.
type ExecutorFunc ¶
type ExecutorFunc func( ctx context.Context, env *Environment, thesis specification.Thesis, ) Result
ExecutorFunc is an adapter to allow the use of ordinary functions as Executor.
func (ExecutorFunc) Execute ¶
func (f ExecutorFunc) Execute( ctx context.Context, env *Environment, thesis specification.Thesis, ) Result
type ExecutorRegistrar ¶
type ExecutorRegistrar func(p *Pipeline)
func WithAssertion ¶
func WithAssertion(executor Executor) ExecutorRegistrar
WithAssertion registers given Executor as assertion.
func WithHTTP ¶
func WithHTTP(executor Executor) ExecutorRegistrar
WithHTTP registers given Executor as HTTP.
type ExecutorType ¶
type ExecutorType string
const ( NoExecutor ExecutorType = "" UnknownExecutor ExecutorType = "!" HTTPExecutor ExecutorType = "HTTP" AssertionExecutor ExecutorType = "assertion" )
type Params ¶
type Params struct { ID string Specification *specification.Specification OwnerID string Started bool }
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is a ready-to-run pipeline created according to the specification, it can be restarted many times, but if the pipeline is running, it cannot be started until executing is over.
func Trigger ¶
func Trigger( id string, spec *specification.Specification, registrars ...ExecutorRegistrar, ) *Pipeline
Trigger creates new Pipeline from specification.Specification.
Trigger receives options that you're free to pass or not. You can pass: WithHTTP, WithAssertion.
func Unmarshal ¶
func Unmarshal(params Params, registrars ...ExecutorRegistrar) *Pipeline
Unmarshal transforms Params to Pipeline. Unmarshal also receives options like Trigger.
This function is great for converting from a database or using in tests.
You must not use this method in business code of domain and app layers.
func (*Pipeline) ShouldBeStarted ¶
ShouldBeStarted returns ErrNotStarted if the Pipeline is not started.
func (*Pipeline) SpecificationID ¶
SpecificationID returns the identifier of the Specification, if it isn't nil, else returns empty string.
func (*Pipeline) Start ¶
Start asynchronously starts executing of the Pipeline. Start returns non buffered chan of flow Step's. With Step's you can build Flow using flow.Reducer.
Only ONE executing can be start at a time. If one goroutine has captured executing, then others calls of Start will be return ErrAlreadyStarted.
func (*Pipeline) WorkingScenarios ¶
func (p *Pipeline) WorkingScenarios() []specification.Scenario
WorkingScenarios returns the specification scenarios that the Pipeline will run.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func Cancel ¶
Cancel returns the canceled Result with occurred error. If the passed error is not equal to TerminatedError with FiredCancel event, it will be wrapped with canceled TerminatedError.
Cancel should be used when you need to mark a thesis as canceled, for example, when context.Context is done. With this result the scenario will be canceled.
func Crash ¶
Crash returns the crashed Result with occurred error. If the passed error is not equal to TerminatedError with FiredCrash event, it will be wrapped with crashed TerminatedError.
Crash should be used when the executing of the thesis has fallen due to unforeseen circumstances, for example, problems with network interaction when executing the HTTP part of the thesis. With this result the scenario will be crashed.
func Fail ¶
Fail returns the failed Result with occurred error. If the passed error is not equal to TerminatedError with FiredFail event, it will be wrapped with failed TerminatedError.
Fail should be used when the executing of the thesis has fallen due to natural reasons, for example, the assertion specified in the thesis failed. With this result the scenario will be failed.
type ScenarioSyncGroup ¶
type ScenarioSyncGroup struct {
// contains filtered or unexported fields
}
ScenarioSyncGroup syncs the executing of theses. SyncDependencies collects all dependencies of scenario into a dependency graph.
Each performing thesis goroutine receives a ScenarioSyncGroup and calls WaitThesisDependencies at the beginning thesis executing. Then each thesis goroutine calls ThesisDone when finished.
func SyncDependencies ¶
func SyncDependencies(scenario specification.Scenario) ScenarioSyncGroup
SyncDependencies collects dependencies within specification.Scenario into one ScenarioSyncGroup, with which will be possible to manage and synchronize the executing of theses, taking into account the dependencies of each thesis.
This can be used inside the pipeline to control the execution of theses, preventing the thesis from being executed if the theses dependent on it are not performed.
func (ScenarioSyncGroup) ScenarioSlug ¶
func (g ScenarioSyncGroup) ScenarioSlug() specification.Slug
ScenarioSlug returns the slug of the scenario for which dependencies are collected.
func (ScenarioSyncGroup) Snapshot ¶
func (g ScenarioSyncGroup) Snapshot() DependenciesSnapshot
Snapshot returns a map representation of dependencies inside the scenario.
func (ScenarioSyncGroup) ThesisDone ¶
func (g ScenarioSyncGroup) ThesisDone(slug specification.Slug)
ThesisDone notifies all pending theses that the thesis with the passed slug are finished.
If the slug is missing in the group, it will have no effect.
func (ScenarioSyncGroup) WaitThesisDependencies ¶
func (g ScenarioSyncGroup) WaitThesisDependencies( ctx context.Context, slug specification.Slug, ) error
WaitThesisDependencies blocks goroutine until all thesis dependencies have finished.
You must pass the thesis slug, the dependencies of which you need to wait for.
type Step ¶
type Step struct {
// contains filtered or unexported fields
}
Step stores information about the executing of slugged objects, such as specification.Scenario and specification.Thesis. It's used to observe the Pipeline execution.
func NewScenarioStep ¶
func NewScenarioStep(slug specification.Slug, event Event) Step
NewScenarioStep returns a Step for the scenario, that is, without the ExecutorType.
Intended only for use with slugs with the specification.ScenarioSlug kind.
func NewScenarioStepWithErr ¶
func NewScenarioStepWithErr(err error, slug specification.Slug, event Event) Step
NewScenarioStepWithErr is similar to NewScenarioStep, only it gets the error that occurred.
Intended only for use with slugs with the specification.ScenarioSlug kind.
func NewThesisStep ¶
func NewThesisStep(slug specification.Slug, pt ExecutorType, event Event) Step
NewThesisStep returns a Step for the thesis.
Intended only for use with slugs with the specification.ThesisSlug kind.
func NewThesisStepWithErr ¶
func NewThesisStepWithErr( err error, slug specification.Slug, pt ExecutorType, event Event, ) Step
NewThesisStepWithErr is similar to NewThesisStep, only it gets the error that occurred.
Intended only for use with slugs with the specification.ThesisSlug kind.
func (Step) ExecutorType ¶
func (s Step) ExecutorType() ExecutorType
ExecutorType returns the ExecutorType if the slug is specification.ThesisSlug, else NoExecutor.
func (Step) Slug ¶
func (s Step) Slug() specification.Slug
Slug returns the slug of the object for which the Step was created.
type TerminatedError ¶
type TerminatedError struct {
// contains filtered or unexported fields
}
func (*TerminatedError) Error ¶
func (e *TerminatedError) Error() string
func (*TerminatedError) Event ¶
func (e *TerminatedError) Event() Event
func (*TerminatedError) Unwrap ¶
func (e *TerminatedError) Unwrap() error
type UndefinedExecutorError ¶
type UndefinedExecutorError struct {
// contains filtered or unexported fields
}
func (*UndefinedExecutorError) Error ¶
func (e *UndefinedExecutorError) Error() string
func (*UndefinedExecutorError) ExecutorType ¶
func (e *UndefinedExecutorError) ExecutorType() ExecutorType