running

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCancelled

func IsCancelled(ctx context.Context) bool

func RunSafely

func RunSafely(ctx context.Context, runnerName string, runner Runner) (err error)

RunSafely executes provided runner with handling of panic. If panic happens, RunSafely returns recovered error, wrapped with additional message, which contains runnerName.

func Server

func Server(
	ctx context.Context,
	log *logan.Entry,
	config ServerConfig,
	handler http.Handler,
)

Server creates http.Server and makes it to ListenAndServe in a separate routine until provided context is cancelled. If Server stops with error - it will be restarted. Server method is blocking, returns after Server's Shutdown() returns.

func UntilSuccess

func UntilSuccess(
	ctx context.Context,
	log Logger,
	runnerName string,
	runner SuccessRunner,
	minRetryPeriod, maxRetryPeriod time.Duration,
)

Until success runs the runner until it returns true,nil or until provided ctx is cancelled. Passed 'log' can be nil - in this case no logging wil happen.

func WithBackoff

func WithBackoff(
	ctx context.Context,
	log Logger,
	runnerName string,
	runner Runner,
	normalPeriod, minRetryPeriod, maxRetryPeriod time.Duration,
)

Types

type Logger

type Logger interface {
	Log(level uint32, fields map[string]interface{}, err error, withStack bool, args ...interface{})
}

Logger is to avoid dependency on any particular logger (logrus and logan loggers implement this interface).

type Runner

type Runner func(context.Context) error

Runner describes how runner function must look like.

type ServerConfig

type ServerConfig struct {
	Address             string
	RequestWriteTimeout time.Duration

	ShutdownPause   time.Duration // optional
	ShutdownTimeout time.Duration // optional
}

TODO Add optional bearer token into config and check Authorization for all requests

func (ServerConfig) GetLoganFields

func (s ServerConfig) GetLoganFields() map[string]interface{}

type SuccessRunner

type SuccessRunner func(context.Context) (bool, error)

SuccessRunner describes how success-runner function must look like.

func CreateSuccessRunner

func CreateSuccessRunner(r Runner) SuccessRunner

CreateSuccessRunner builds a SuccessRunner function out of the Runner function.

Jump to

Keyboard shortcuts

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