runtime

package
v0.0.0-...-a93a756 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package runtime contains types which aid in the building of runtimes and runtime calls which can be constructed and invoked by the agent types.

The *Builder type aids in composing types which avoid having to do manual parsing to and from metadata fields on adagio.Node types.

The `runtime.Function()` is a handy function which takes a type with the behavior for parsing an incoming node (`Parse(*adagio.Node) error`) and running the function once parsed (`Run() (*adagio.Result, error)`) as separate calls and combines them in a agent.Function compatible implementation. This allows for a *runtime.Builder to be embedded into new Function definitions, which can then take on the responsibility of the `Parse(node) error` call. All you need to do is define and configure the named arguments of your function using the helper methods on the builder and then a single `Run()` implementation which takes care of invoking your functions behavior. For example, `builder.String(&str, "foo", false, "bar")` will add an argument "foo" which is not required and defaults to the value "bar".

The following is a contrived example of implementing the Runtime and Function types used the *Builder helper type.

package thing

import "github.com/georgemac/adagio/pkg/agent"

const name = "thing"

type Runtime struct {}

func (r Runtime) Name() string { return name }

func (r Runtime) BlankFunction() agent.Function {
    return runtime.Function(blankFunction())
}
func blankFunction() *Function {
    call := &Function{Builder: runtime.New(name)}

    call.String("string_arg", true, "default")(&call.StringArg)
    call.Strings("strings_arg", false, "many", "default")(&call.StringsArg)

    return call
}
type Function struct {
    *runtime.Builder
    StringArg  string
    StringsArg []string
}
func NewFunction(stringArg string, extraStringArgs ...string) *Function {
    call := blackFunction()
    call.StringArg = stringArg
    call.StringsArg = extraStringArgs

    return call
}
func (c *Function) Run() error {
    // do the things with the arguments
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name     string
	Type     ArgumentType
	Required bool
	Defaults []string
	// contains filtered or unexported fields
}

Argument is a structure which contains the properties of a argument used to call a runtime

func (*Argument) SetToDefault

func (f *Argument) SetToDefault() error

SetToDefault applies the default values to the argument

type ArgumentType

type ArgumentType uint8

ArgumentType is a type of argument

const (
	// StringArgumentType represents a string type argument
	StringArgumentType ArgumentType = iota
	// StringsArgumentType represents a slice of string types argument
	StringsArgumentType
	// Int64ArgumentType represents an int64 type argument
	Int64ArgumentType
	// TimeArgumentType represent a time.Time type argument
	TimeArgumentType
	// JSONArgumentType represents any value marshalled to and from using JSON
	JSONArgumentType
)

func (ArgumentType) String

func (t ArgumentType) String() string

String prints a string representation of the argument type

type Builder

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

Builder is a struct aids in both parsing and construction of runtimes and runtime request types

func NewBuilder

func NewBuilder(name string) *Builder

NewBuilder constructs and configures a new runtime builder

func (*Builder) Int64

func (b *Builder) Int64(v *int64, name string, required bool, defaultValue int64)

Int64 configures an int64 argument which will set the pointer on calls to builder.Parse() and read the value at the end of the pointer on calls to builder.NewSpec()

func (*Builder) JSON

func (b *Builder) JSON(v interface{}, name string, required bool)

JSON configures an argument which should be called with a pointer to any json marshallable type It will set the pointer on calls to builder.Parse() by calling unmarshal on the pointer and read the value at the end of the pointer and marshal it on calls to builder.NewSpec()

func (*Builder) Name

func (b *Builder) Name() string

Name returns the name of the runtime being built

func (*Builder) NewSpec

func (b *Builder) NewSpec(name string) (*adagio.Node_Spec, error)

NewSpec constructs a Node_Spec based on the current state of the builders arguments

func (*Builder) Parse

func (b *Builder) Parse(node *adagio.Node) error

Parse parses the state from a node into the targets set on the builders arguments

func (*Builder) SetArgumentFromInput

func (b *Builder) SetArgumentFromInput(argument, name string) error

SetArgumentFromInput configures the argument to derives its value from the input paramertes of the node

func (*Builder) String

func (b *Builder) String(v *string, name string, required bool, defaultValue string)

String configures a string argument which when call with a string pointer will set the pointer on calls to builder.Parse() and read the value at the end of the pointer on calls to builder.NewSpec()

func (*Builder) Strings

func (b *Builder) Strings(v *[]string, name string, required bool, defaultValues ...string)

Strings configures a string slice argument which when call with a string slice pointer will set the pointer on calls to builder.Parse() and read the value at the end of the pointer on calls to builder.NewSpec()

func (*Builder) Time

func (b *Builder) Time(v *time.Time, name string, required bool, defaultValue time.Time)

Time configures a time argument which when call with a int64 pointer will set the pointer on calls to builder.Parse() and read the value at the end of the pointer on calls to builder.NewSpec()

type FunctionAdaptor

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

FunctionAdaptor is the type used to covert a ParseRunner into a agent.Function compatable type

func Function

func Function(runner ParseRunner) FunctionAdaptor

Function converts the provided ParseRunner into a agent.Function using the FunctionAdaptor wrapper type

func (FunctionAdaptor) Run

Run calls Parse on the provided node and then invokes Run on the underlying ParseRunner

type ParseRunner

type ParseRunner interface {
	Parse(n *adagio.Node) error
	Run(ctx context.Context) (*adagio.Result, error)
}

ParseRunner is a type which has a separate function for parsing a node and then invoking the desired behavior via Run

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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