runner

package module
v0.0.0-...-5080d2f Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

runner

A one function call that receives multiple lifecycle managed resources and run them until the application terminates.

License GoDoc TravisCI Codecov Go Report Card

Documentation

Please refer to the godoc pages for documentation.

Versioning

This project release version format follows Semantic Versioning.

Contributing

Pull requests and issue reports are welcomed.

License

This project is licensed under Apache License Version 2.0

Documentation

Overview

Package runner provides an interface to define the lifecycle of service like components and a function to manage them.

Brief

This library provides a way to manage the lifecycle of service like components.

Usage

$ go get -u github.com/adzr/runner

Then, import the package:

import (
  "github.com/adzr/runner"
)

Finally, just implement the Runnable interface and pass it to the Run() function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(hcInterval time.Duration, runnables ...Runnable)

Run receives Runnable implementations and a health check time interval then and calls the Start() method of each Runnable in a separate go-routine and then the Check() method of each in a separate go-routine periodically based on the time interval received, and then the function blocks waiting for one of the system signals (syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT). If a signal is received then it doesn't call Runnable.Check() anymore and calls the Stop() method of each Runnable in a separate go-routine and wait them all to finish and finally returns.

Types

type Runnable

type Runnable interface {

	// Start is being called in a separate go-routine as soon as this object
	// is passed to the Run() function to switch the implementation
	// to "running" mode.
	// It must return an error if it fails to start for any reason, nil otherwise.
	Start() error

	// Stop is being called in a separate go-routine once one of the termination
	// signals (syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) has been sent
	// to the application.
	// It must return an error if it fails to stop for any reason, nil otherwise.
	Stop() error

	// Check is being called in a separate go-routine after all the "Runnable"s
	// have started, this is called periodically every certain time duration
	// passed as a parameter to the Run() function, the periodic call stops when
	// Stop() method is called.
	// It must return an error if the check fails for any reason, nil otherwise.
	Check() error

	// OnError handles any error returned by the other methods.
	OnError(err error)
}

Runnable represents anything that can be run in a separate go-routine, this is an ideal interface for a service type components that can run concurrently in the same application.

Jump to

Keyboard shortcuts

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