runnable

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MIT Imports: 8 Imported by: 16

README

Runnable

GoDoc Go Report Card

Tooling to manage the execution of components (intra process).

Work in progress

License

The MIT License (MIT)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunGroup added in v0.1.0

func RunGroup(runners ...Runnable)

RunGroup runs all runnables in a Group, and listen to SIGTERM/SIGINT

Types

type GroupRunner

type GroupRunner struct {
	ShutdownTimeout time.Duration
	// contains filtered or unexported fields
}

func Group

func Group(runnables ...Runnable) *GroupRunner

Group returns a runnable that concurrently runs all runnables passed in argument.

func (*GroupRunner) Run

func (g *GroupRunner) Run(ctx context.Context) error

type Logger

type Logger interface {
	// Warnf logs with a warning level.
	Warnf(format string, args ...interface{})

	// Infof logs with an info level.
	Infof(format string, args ...interface{})

	// Debugf logs with a debug level.
	Debugf(format string, args ...interface{})
}

type PanicError

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

func (*PanicError) Error

func (e *PanicError) Error() string

func (*PanicError) Unwrap

func (e *PanicError) Unwrap() error

type PeriodicOptions added in v0.1.0

type PeriodicOptions struct {
	Period time.Duration
}

PeriodicOptions configures the behavior of a Periodic runnable.

type RecoverRunner

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

func (*RecoverRunner) Run

func (r *RecoverRunner) Run(ctx context.Context) (err error)

type RestartOptions

type RestartOptions struct {
	RestartLimit int // Number of restart after which the runnable will not be restarted.
	CrashLimit   int // Number of crash after which the runnable will not be restarted.

	BackoffSleep      time.Duration // Time to wait before restarting.
	CrashBackoffSleep time.Duration // Time to wait before restarting after a crash

}

RestartOptions configures the behavior of the Restart runnable

type Runnable

type Runnable interface {
	Run(context.Context) error
}

Runnable is the contract for anything that runs with a Go context, respects the concellation contract, and expects the caller to handle errors.

func Periodic added in v0.1.0

func Periodic(opts PeriodicOptions, runnable Runnable) Runnable

Periodic returns a runnable that will periodically run the runnable passed in argument.

func Recover

func Recover(runnable Runnable) Runnable

Recover returns a runnable that recovers when a runnable panics and return an error to represent this panic.

func Restart

func Restart(opts RestartOptions, runnable Runnable) Runnable

Restart returns a runnable that runs a runnable and restarts it when it fails, with some conditions.

func Signal

func Signal(runnable Runnable, signals ...os.Signal) Runnable

Signal returns a runnable that runs the runnable and cancels it when the process receives a POSIX signal.

Directories

Path Synopsis
cmd
test command
examples
loggers module

Jump to

Keyboard shortcuts

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