runner

package
v6.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyChained = "__EMPTY_CHAINED__"

EmptyChained in a token used to represent a chained parameter value that could not be resolved due to a failed response from the upstream dependency.

Variables

View Source
var (
	// ErrQueryTimedOut represents the event of a query that
	// exceed the maximum execution time for it.
	ErrQueryTimedOut = errors.New("query timed out")

	// ErrMaxQueryDenied represents the event when restQL reaches the maximum
	// number of concurrent queries and cannot process anymore.
	ErrMaxQueryDenied = errors.New("max concurrent query reached: query execution denied")

	// ErrMaxGoroutineDenied represents the event when restQL reaches the maximum
	// number of concurrent goroutines and cannot process anymore.
	ErrMaxGoroutineDenied = errors.New("max concurrent goroutine reached: statement execution denied")
)
View Source
var ErrInvalidChainedParameter = errors.New("chained parameter targeting unknown statement")

ErrInvalidChainedParameter represents an error when a chain parameter value references an unknown statement.

View Source
var ErrInvalidDependsOnTarget = errors.New("depends-on targets an unknown resource")

ErrInvalidDependsOnTarget represents an error when a depends-on target references an unknown statement.

Functions

func ApplyEncoders

func ApplyEncoders(resources domain.Resources, log restql.Logger) domain.Resources

ApplyEncoders transform parameter values with encoder functions applied into a Resource collection with the values processed.

func ApplyModifiers

func ApplyModifiers(resources domain.Resources, modifiers domain.Modifiers) domain.Resources

ApplyModifiers transforms an unresolved Resources collection and set the query level cache directives into each statement without cache directives.

func GetEmptyChainedParams

func GetEmptyChainedParams(statement domain.Statement) []string

GetEmptyChainedParams returns the chain parameters that could not be resolved.

func MakeRequest

func MakeRequest(defaultResourceTimeout time.Duration, forwardPrefix string, statement domain.Statement, queryCtx restql.QueryContext) restql.HTTPRequest

MakeRequest builds a HTTPRequest from a statement.

func MultiplexStatements

func MultiplexStatements(resources domain.Resources) domain.Resources

MultiplexStatements creates a statement for each value in a list parameter value. In case of multiple list parameter values it makes the cartesian product of all the lists and makes a statement for each value in a result product.

func NewDoneResource

func NewDoneResource(request restql.HTTPRequest, response restql.HTTPResponse, options DoneResourceOptions) restql.DoneResource

NewDoneResource constructs a DoneResourceOptions value.

func NewEmptyChainedResponse

func NewEmptyChainedResponse(log restql.Logger, params []string, options DoneResourceOptions) restql.DoneResource

NewEmptyChainedResponse builds a DoneResource for a statement with unresolved chain parameters.

func NewErrorResponse

func NewErrorResponse(log restql.Logger, err error, request restql.HTTPRequest, response restql.HTTPResponse, options DoneResourceOptions) restql.DoneResource

NewErrorResponse builds a DoneResource value for a failed HTTP call.

func NewNewDependsOnUnresolvedResponse

func NewNewDependsOnUnresolvedResponse(log restql.Logger, stmt domain.Statement, options DoneResourceOptions) restql.DoneResource

func ResolveChainedValues

func ResolveChainedValues(resources domain.Resources, doneResources domain.Resources) domain.Resources

ResolveChainedValues takes an unresolved Resource collection and replace chain parameter values by data present in the done Resource collection.

func ResolveDependsOn

func ResolveDependsOn(resources domain.Resources, doneResources domain.Resources) domain.Resources

ResolveDependsOn takes an unresolved Resource collection and find if a resource dependency was successfully resolved

func UnwrapNoMultiplex

func UnwrapNoMultiplex(resources domain.Resources) domain.Resources

UnwrapNoMultiplex transform a collection of unresolved Resources with `no-multiplex` functions into a collection of Resources without it.

func ValidateChainedValues

func ValidateChainedValues(resources domain.Resources) error

ValidateChainedValues returns an error if a chain parameter value references an unknown statement.

func ValidateDependsOnTarget

func ValidateDependsOnTarget(resources domain.Resources) error

ValidateDependsOnTarget returns an error if a depends-on target references an unknown statement.

Types

type DoneResourceOptions

type DoneResourceOptions struct {
	Debugging    bool
	IgnoreErrors bool
	MaxAge       interface{}
	SMaxAge      interface{}
}

DoneResourceOptions represents information from the statement that should be passed to the result.

type Executor

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

Executor process statements into a result by executing the relevant HTTP calls to the upstream dependency.

func NewExecutor

func NewExecutor(log restql.Logger, client domain.HTTPClient, resourceTimeout time.Duration, forwardPrefix string) Executor

NewExecutor constructs an instance of Executor.

func (Executor) DoStatement

func (e Executor) DoStatement(ctx context.Context, statement domain.Statement, queryCtx restql.QueryContext) restql.DoneResource

DoStatement process a single statement into a result by executing the relevant HTTP calls to the upstream dependency.

type Options

type Options struct {
	GlobalQueryTimeout      time.Duration
	MaxConcurrentQueries    int
	MaxConcurrentGoroutines int
}

Options wraps all configuration parameters for the Runner

type Runner

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

Runner process a query into a Resource collection with the results in the most efficient way. All statements that can be executed in parallel, hence not having co-dependency, are done so.

func NewRunner

func NewRunner(log restql.Logger, executor Executor, options Options) Runner

NewRunner returns a Runner instance.

func (Runner) ExecuteQuery

func (r Runner) ExecuteQuery(ctx context.Context, query domain.Query, queryCtx restql.QueryContext) (domain.Resources, error)

ExecuteQuery process a query into a Resource collection.

type State

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

State tracks the status of the statements to be resolved being resolved and done.

func NewState

func NewState(todo domain.Resources) *State

NewState constructs a State value.

func (*State) Available

func (s *State) Available() domain.Resources

Available return all statements to be resolved that have no dependency or which dependency was resolved.

func (*State) Done

func (s *State) Done() domain.Resources

Done returns all Resources already resolved

func (*State) HasFinished

func (s *State) HasFinished() bool

HasFinished returns true if all Resources are set as done.

func (*State) Requested

func (s *State) Requested() domain.Resources

Requested returns all Resources being resolved

func (*State) SetAsRequest

func (s *State) SetAsRequest(resourceID domain.ResourceID)

SetAsRequest define an to be resolved Resource into a being resolved Resource.

func (*State) UpdateDone

func (s *State) UpdateDone(resourceID domain.ResourceID, response interface{})

UpdateDone set a being resolved Resource as done.

Jump to

Keyboard shortcuts

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