pipeline

package
v0.0.0-...-044f632 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyStarted = errors.New("pipeline already started")
	ErrNotStarted     = errors.New("pipeline not started")
)

Functions

func NewUndefinedExecutorError

func NewUndefinedExecutorError(executorType ExecutorType) error

func WrapWithTerminatedError

func WrapWithTerminatedError(err error, event Event) error

Types

type DependenciesSnapshot

type DependenciesSnapshot map[specification.Slug][]specification.Slug

func (DependenciesSnapshot) Equal

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 Event

type Event string

Event is fired due to the creation of the Result.

const (
	NoEvent      Event = ""
	FiredExecute Event = "execute"
	FiredPass    Event = "pass"
	FiredFail    Event = "fail"
	FiredCrash   Event = "crash"
	FiredCancel  Event = "cancel"
)

func (Event) String

func (e Event) String() string

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) ID

func (p *Pipeline) ID() string

ID returns the identifier of the Pipeline.

func (*Pipeline) MustStart

func (p *Pipeline) MustStart(ctx context.Context) <-chan Step

MustStart is similar to Start, but instead of the error it panics.

func (*Pipeline) OwnerID

func (p *Pipeline) OwnerID() string

OwnerID return the identifier of the Pipeline owner.

func (*Pipeline) ShouldBeStarted

func (p *Pipeline) ShouldBeStarted() error

ShouldBeStarted returns ErrNotStarted if the Pipeline is not started.

func (*Pipeline) SpecificationID

func (p *Pipeline) SpecificationID() string

SpecificationID returns the identifier of the Specification, if it isn't nil, else returns empty string.

func (*Pipeline) Start

func (p *Pipeline) Start(ctx context.Context) (<-chan Step, error)

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) Started

func (p *Pipeline) Started() bool

Started indicates whether the Pipeline is running.

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

func Cancel(err error) Result

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

func Crash(err error) Result

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

func Fail(err error) Result

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.

func Pass

func Pass() Result

Pass returns the passed Result.

Pass should be used when the thesis is passed, with this result the scenario executing will continue.

func (Result) Err

func (r Result) Err() error

Err returns occurred error of the Result.

func (Result) Event

func (r Result) Event() Event

Event returns event of the Result.

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

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) Err

func (s Step) Err() error

Err returns the error occurred at the Step.

func (Step) Event

func (s Step) Event() Event

Event returns the event fired at the Step.

func (Step) ExecutorType

func (s Step) ExecutorType() ExecutorType

ExecutorType returns the ExecutorType if the slug is specification.ThesisSlug, else NoExecutor.

func (Step) IsZero

func (s Step) IsZero() bool

IsZero returns true if the Step is empty, else false.

func (Step) Slug

func (s Step) Slug() specification.Slug

Slug returns the slug of the object for which the Step was created.

func (Step) String

func (s Step) String() string

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

Jump to

Keyboard shortcuts

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