beam: Index | Files

package hooks

import ""

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.


Package Files


func Decode Uses

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 Uses

func DeserializeHooksFromOptions(ctx context.Context)

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

func EnableHook Uses

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 Uses

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 Uses

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

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

func RegisterHook Uses

func RegisterHook(name string, h HookFactory)

RegisterHook registers a Hook for the supplied identifier.

func RunInitHooks Uses

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

RunInitHooks runs the init hooks.

func RunRequestHooks Uses

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

RunRequestHooks runs the hooks that handle a FnAPI request.

func RunResponseHooks Uses

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

RunResponseHooks runs the hooks that handle a FnAPI response.

func SerializeHooksToOptions Uses

func SerializeHooksToOptions()

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

type Hook Uses

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 Uses

type HookFactory func([]string) Hook

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

type InitHook Uses

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

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

type RequestHook Uses

type RequestHook func(context.Context, *fnpb.InstructionRequest) (context.Context, error)

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 Uses

type ResponseHook func(context.Context, *fnpb.InstructionRequest, *fnpb.InstructionResponse) error

ResponseHook is called when sending a FnAPI instruction response.

Package hooks imports 9 packages (graph) and is imported by 5 packages. Updated 2019-06-13. Refresh now. Tools for package owners.