floop

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

README

floop   Build Status

Floop is an integration tool which can be used to provide event-based lifecycle data for any process, without requiring any code changes which would couple your application to its consumer. It currently supports integration with STDOUT, HTTP and NATS endpoints, with near-term plans to add additional protocols.

Integration actions can be configured for the following lifecycle events:

  • Begin
  • Progress
  • Completed
  • Failed

Examples

Floop is currently configured with a single configuration file. The following example will post JSON to a single endpoint when the find process starts and when it completes.

Running Floop

floop reference_id=1234 -exec find . -name filename

Configuring Floop
meta:
  - reference_id

handlers:
  begin:
  - type: http
    uri: "http://my-status-service/${Meta.REFERENCE_ID}"
    options:
      method: "POST"
    body: |
        {
            "status": "started",
        }      
  completed:
  - type: http
    uri: "http://my-status-service/${Meta.REFERENCE_ID}"
    options:
      method: "POST"
    body: |
        {
            "status": "completed",
        }   

Additional configuration examples can be found under the test-data directory.

Contributing

The purpose of this repository is to continue to evolve floop, adding additional integration protocols and configuration options. All development is done publicly on GitHub, and we look forward to working with a community of both users and developers to make floop even more powerful and intuitive.

Please see the Contributing Guide for additional inforamtion on how to open issues or submit pull requests.

Documentation

Index

Constants

View Source
const VERSION = "0.1.7"

VERSION number

Variables

This section is empty.

Functions

func Transform

func Transform(transform []string, input []byte, out *types.Event) (transformed bool, err error)

Transform transforms the input given the transform and writes it to the event data

func TransformResult added in v0.1.3

func TransformResult(transform types.TransformConfig, input *types.ChildResult, out *types.Event) (transformed bool, err error)

TransformResult transforms the input given the transform and writes it to the event data

Types

type BufferedWriter

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

BufferedWriter is a writer that buffers all the data on top of a callback buffer writer

func NewBufferedWriter

func NewBufferedWriter(cb func([]byte), buffer bool) *BufferedWriter

NewBufferedWriter instantiates a new BufferedWriter. The cb is called each time a wrie ending in a new line is found. If buffer is true a data copy is kept internally which can be used later.

func (*BufferedWriter) Bytes

func (wr *BufferedWriter) Bytes() []byte

Bytes returns all bytes written till now. If the internal buffer is not enabled nil is returned

func (*BufferedWriter) Write

func (wr *BufferedWriter) Write(b []byte) (int, error)

Write writes the byte slice using the configured writer function

type Config

type Config struct {
	Command        string
	Args           []string
	Meta           []string // required meta keys
	Quiet          bool
	ResolverHosts  []string `yml:"resolverhost"`
	ResolverPort   int      `yml:"resolverport"`
	Handlers       map[types.EventType][]*types.HandlerConfig
	ReadFromStderr bool `yml:"stderr"`
}

Config is the overall config.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with defaults using the echo Lifecycle

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig loads a config from the file given by filename

func (*Config) HasMeta

func (conf *Config) HasMeta(meta map[string]interface{}) bool

HasMeta checks if the input meta has the required metadata keys

type Floop

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

Floop is the core interface that manages the process lifecycle and handlers

func New

func New(conf *Config, input *child.NewInput) (*Floop, error)

New instantiates a new instance of floop.

func (*Floop) Start

func (floop *Floop) Start(meta map[string]interface{}) error

Start calls the begin phase of the lifecycle and starts the child process

func (*Floop) Wait

func (floop *Floop) Wait() int

Wait waits for the child process to exit and calls the end phase of the lifecycle

type Handler

type Handler interface {
	// raw event and config after interpolation
	Handle(event *types.Event, conf *types.HandlerConfig) (map[string]interface{}, error)
	Init(conf *types.HandlerConfig) error
	CloseConnection() error
}

Handler represents the event handler interface.

type Lifecycle

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

Lifecycle implements a Lifecycle that calls multiple lifecycles for an event.

func NewLifecycle

func NewLifecycle(conf *Config) (*Lifecycle, error)

NewLifecycle instantiates an instance of Lifecycle

func (*Lifecycle) Begin

func (lc *Lifecycle) Begin(ctx *types.Context) error

Begin is called right before a process is launched. The context is internally stored and may be updated by subsequent phases from callback responses.

func (*Lifecycle) Canceled added in v0.1.4

func (lc *Lifecycle) Canceled(result *types.ChildResult)

Canceled is called if the process was interrupted or killed. Data from stderr and stdout are passed in as args

func (*Lifecycle) Close added in v0.1.3

func (lc *Lifecycle) Close()

Close - close completed and failed handlers so the last event is published

func (*Lifecycle) Completed

func (lc *Lifecycle) Completed(result *types.ChildResult)

Completed is called when a process completes with a zero exit code. Data from stderr and stdout are passed in as args

func (*Lifecycle) Failed

func (lc *Lifecycle) Failed(result *types.ChildResult)

Failed is called if the process exits with a non-zero exit status. Data from stderr and stdout are passed in as args

func (*Lifecycle) Progress

func (lc *Lifecycle) Progress(line []byte)

Progress echos the progress payload

type Result added in v0.1.3

type Result struct {
	Code   int // exit code
	Stdout interface{}
	Stderr interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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