ops

package module
v0.0.0-...-d70cb0d Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: Apache-2.0 Imports: 3 Imported by: 39

Documentation

Overview

Package ops provides a facility for tracking the processing of operations, including contextual metadata about the operation and their final success or failure. An op is assumed to have succeeded if by the time of calling Exit() no errors have been reported. The final status can be reported to a metrics facility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsMap

func AsMap(obj interface{}, includeGlobals bool) context.Map

AsMap mimics the method from context.Manager.

func Go

func Go(fn func())

Go mimics the method from context.Manager.

func RegisterReporter

func RegisterReporter(reporter Reporter)

RegisterReporter registers the given reporter.

func SetGlobal

func SetGlobal(key string, value interface{})

SetGlobal puts a key->value pair into the global context, which is inherited by all Ops.

func SetGlobalDynamic

func SetGlobalDynamic(key string, valueFN func() interface{})

SetGlobalDynamic is like SetGlobal but uses a function to derive the value at read time.

Types

type Op

type Op interface {
	// Begin marks the beginning of an Op under this Op.
	Begin(name string) Op

	// Go starts the given function on a new goroutine.
	Go(fn func())

	// End marks the end of this op, at which point the Op will report its success
	// or failure to all registered Reporters.
	End()

	// Cancel cancels this op so that even if End() is called later, it will not
	// report its success or failure.
	Cancel()

	// Set puts a key->value pair into the current Op's context.
	Set(key string, value interface{}) Op

	// SetDynamic puts a key->value pair into the current Op's context, where the
	// value is generated by a function that gets evaluated at every Read.
	SetDynamic(key string, valueFN func() interface{}) Op

	// FailIf marks this Op as failed if the given err is not nil. If FailIf is
	// called multiple times, the latest error will be reported as the failure.
	// Returns the original error for convenient chaining.
	FailIf(err error) error
}

Op represents an operation that's being performed. It mimics the API of context.Context.

func Begin

func Begin(name string) Op

Begin marks the beginning of a new Op.

type Reporter

type Reporter func(failure error, ctx map[string]interface{})

Reporter is a function that reports the success or failure of an Op. If failure is nil, the Op can be considered successful.

Jump to

Keyboard shortcuts

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