Giter VIP home page Giter VIP logo

conductor's Introduction

Conductor Logo

Conductor does the least amount possible to solve the problem of starting up dependant services and shutting them down gracefully.

Implementing a service:

A service implements the conductor.Service interface via a Run method which takes 3 channels:

  • started chan bool - Send true when your service is running
  • stopped chan bool - Send true when your service has stopped
  • stop chan context.Context - Select on this to be notified of shutdown, context with timeout.
type MyService struct {}

func (t MyService) Run(started, stopped chan bool, stop chan context.Context) error {
    go func() {
      // Do some startup stuff then signal we're running
      started <- true
      select {
        case ctx := <- stop:
          // do some shutdown stuff then signal we're done
          stopped <- true
      }
    }()
    return nil
}

Starting your services:

c := conductor.New()
c.Service("Service 1", MyService{})
c.Service("Service 2", MyService{})
<- c.Start() // wait for graceful shutdown

Stopping:

You can call Conductor.Stop() which will close the Shutdown channel returned by Conductor.Start() once all services have closed or timeout is reached.

Options!

Everyone loves options, these functions can all have their return values passed to Conductor.Run to modify the behaviour of the Conductor.

  • HookSignals() Will tell the conductor to listen for kill/stop signals and shutdown services.
  • StartupTimeout(time.Duration) How long to wait for a service to start (Default 5s).
  • ShutdownTimeout(time.Duration) How long to wait for a service to stop gracefully (Default 5s).
  • Noisy() Log services starting and stopping via standard log.
c := conductor.New(
    conductor.HookSignals(),
    conductor.Noisy(),
    conductor.ShutdownTimeout(time.Duration(20 * time.Second)))

conductor's People

Stargazers

Great avatar Ishan Goel avatar n0nimouse avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.