hooks

package
v2.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: Apache-2.0, BSD-3-Clause, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package hooks allows runners to tailor execution of the worker harness.

Examples of customization:

gRPC integration session recording profile recording

Registration methods for hooks must be called prior to calling beam.Init() Request methods for hooks must be called as part of building the pipeline request for the runner's Execute method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(in string) (string, []string)

Decode decodes a hook name and its arguments from a single string. This is a convenience function for users of this package that are composing hooks.

func DeserializeHooksFromOptions

func DeserializeHooksFromOptions(ctx context.Context)

DeserializeHooksFromOptions extracts the hook configuration information from the options and configures the hooks with the supplied options.

func EnableHook

func EnableHook(name string, args ...string) error

EnableHook enables the hook to be run for the pipline. It will be receive the supplied args when the pipeline executes. It is safe to enable the same hook with different options, as this is necessary if a hook wants to compose behavior.

func Encode

func Encode(name string, opts []string) string

Encode encodes a hook name and its arguments into a single string. This is a convenience function for users of this package that are composing hooks.

func IsEnabled

func IsEnabled(name string) (bool, []string)

IsEnabled returns true and the registered options if the hook is already enabled.

func RegisterHook

func RegisterHook(name string, h HookFactory)

RegisterHook registers a Hook for the supplied identifier.

func RunInitHooks

func RunInitHooks(ctx context.Context) (context.Context, error)

RunInitHooks runs the init hooks.

func RunRequestHooks

func RunRequestHooks(ctx context.Context, req *fnpb.InstructionRequest) context.Context

RunRequestHooks runs the hooks that handle a FnAPI request.

func RunResponseHooks

func RunResponseHooks(ctx context.Context, req *fnpb.InstructionRequest, resp *fnpb.InstructionResponse)

RunResponseHooks runs the hooks that handle a FnAPI response.

func SerializeHooksToOptions

func SerializeHooksToOptions()

SerializeHooksToOptions serializes the activated hooks and their configuration into a JSON string that can be deserialized later by the runner.

Types

type Hook

type Hook struct {
	// Init is called once at the startup of the worker prior to
	// connecting to the FnAPI services.
	Init InitHook
	// Req is called each time the worker handles a FnAPI instruction request.
	Req RequestHook
	// Resp is called each time the worker generates a FnAPI instruction response.
	Resp ResponseHook
}

A Hook is a set of hooks to run at various stages of executing a pipeline.

type HookFactory

type HookFactory func([]string) Hook

HookFactory is a function that produces a Hook from the supplied arguments.

type InitHook

type InitHook func(context.Context) (context.Context, error)

InitHook is a hook that is called when the harness initializes.

type RequestHook

RequestHook is called when handling a FnAPI instruction. It can return an updated context to pass additional information to downstream callers, or return the original context provided.

type ResponseHook

ResponseHook is called when sending a FnAPI instruction response.

Jump to

Keyboard shortcuts

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