Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultPoolSize = 15
DefaultPoolSize represents the total number of goroutines that this executor pool shares. In the future this may be configurable and/or dependent on the number of services specified in configuration
var ErrTimeoutExceeded = errors.New("Execution timeout exceeded")
ErrTimeoutExceeded is an err that indicates the configured timeout for the execution has been exceeded. Timeout for executors can be set by setting the "timeout" property in the executor specification. The units are in seconds for this field.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor interface {
// Execute will run the wrapped function.
// All errors are logged to the Service diagnostics
//
// Context is used for cancellation of the running Executors
Execute(context.Context) error
}
An executor is an abstractions that represents some parameterless invocation. Executors are run when a Condition is satisfied.
type ExecutorFunc ¶
ExecutorFunc defines the method signature that all Executors must follow
type Http ¶
type Http struct {
LogResponse bool `yaml:"log"`
Body string `yaml:"body"`
Method string `yaml:"method"`
Headers map[string]string `yaml:"headers"`
URL string `yaml:"url"`
Timeout int `yaml:"timeout"`
// contains filtered or unexported fields
}
Http is an implementation of Executor that makes HTTP Requests.
func NewHttp ¶
func NewHttp(logger logrus.FieldLogger, client http.Client) *Http
NewHttp constructs an HTTP struct with only its dependencies and defaults provided. Binding to configuration is done elsewhere in the struct lifecycle.
func (*Http) Execute ¶
Execute complete a HTTP Request with parameters defined by the Http struct on which the execution is run. context.Context is used here to propagate any cancellation requests from the caller to the HTTP Client making the request. An additional timeout constraint is placed over the HTTP Request context, the length of this timeout is driven by the configuration defined in Http
type Job ¶
type Job struct {
Service string
Executor ExecutorFunc
}
Job represents a unit of work to be run by the executor pool triggered by a Service definitions condition(s) being satisfied Jobs can be run by adding them to the pool backlog via:
pool.Enqueue(job)
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents a collection of workers that can be used by `executor.Execute` to dispatch work
func NewPool ¶
func NewPool(logger logrus.FieldLogger, size int) *Pool
NewPool constructs a new executor pool
func (*Pool) Start ¶
func (pool *Pool) Start()
Start spawns N executors in the pool. If the pool is already running then the operations is a no-op
Closing of the pool is completed using:
pool.Stop(context.Context)
func (*Pool) Stop ¶
Stop closes all running goroutines that are members of the execution pool, each executor is also instructured to cancel execution by an internal context.
The context passed to the Stop method can be used to abort the shutdown of the executor pool e.g.
ctx, _ := context.WithTimeout(context.Background(), time.Second) err := pool.Stop(ctx)
type Shell ¶
type Shell struct {
LogOutput bool `yaml:"log"`
Shell string `yaml:"shell"`
Command string `yaml:"command"`
Timeout int `yaml:"timeout"`
// contains filtered or unexported fields
}
Shell defines an execution that will run in the users defined shell. The command that will be run is specified via the Command member of this struct.
Defaults: - Logging output is disabled - Timeout for commands is 5s
func NewShell ¶
func NewShell(logger logrus.FieldLogger) *Shell
NewShell creates a new Shell based executor with default values set for optional fields in the configuration and all dependencies