shezmu

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

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

Go to latest
Published: Jul 26, 2016 License: MIT Imports: 11 Imported by: 0

README

Shezmu

Shezmu is a daemon execution platform for Go apps.

  • What is a daemon execution platform?
  • What does it provide?
  • How does it work?
  • What is a daemon?
  • What is an actor/task/process?
  • General example
  • Consumer example
  • Message queues
  • Dashboard

Documentation

Index

Constants

View Source
const (
	// DefaultNumWorkers is the default number of workers that would process
	// tasks.
	DefaultNumWorkers = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor func()

Actor is a function that could be executed by daemon workers.

type BaseDaemon

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

BaseDaemon is the parent structure for all daemons.

func (*BaseDaemon) Continue

func (d *BaseDaemon) Continue() bool

Continue returns true if daemon should proceed and false if it should stop.

func (*BaseDaemon) HandlePanics

func (d *BaseDaemon) HandlePanics(f PanicHandler)

HandlePanics sets up a panic handler function for the daemon.

func (*BaseDaemon) LimitRate

func (d *BaseDaemon) LimitRate(times int, per time.Duration)

LimitRate limits the daemons' processing rate.

func (*BaseDaemon) Log

func (d *BaseDaemon) Log(v ...interface{})

Log logs values using shezmu.Logger.Println function.

func (*BaseDaemon) Logf

func (d *BaseDaemon) Logf(format string, v ...interface{})

Logf logs values using shezmu.Logger.Printf function.

func (*BaseDaemon) Process

func (d *BaseDaemon) Process(a Actor)

Process creates a task and then adds it to processing queue.

func (*BaseDaemon) Shutdown

func (d *BaseDaemon) Shutdown()

Shutdown is the empty implementation of the daemons' Shutdown function that is inherited and used by default.

func (*BaseDaemon) ShutdownRequested

func (d *BaseDaemon) ShutdownRequested() <-chan struct{}

ShutdownRequested returns a channel that is closed the moment daemon shutdown is requested.

func (*BaseDaemon) Startup

func (d *BaseDaemon) Startup()

Startup is the empty implementation of the daemons' Startup function that is inherited and used by default.

func (*BaseDaemon) String

func (d *BaseDaemon) String() string

String returns the name of the Deamon unerlying struct.

func (*BaseDaemon) SystemProcess

func (d *BaseDaemon) SystemProcess(name string, a Actor)

SystemProcess creates a system task that is restarted in case of failure and then adds it to processing queue.

type Daemon

type Daemon interface {
	// Startup implementation should:
	//
	// func (d *DaemonName) Startup() {
	//     // 1. Set up a panic handler
	//     b.HandlePanics(func() {
	//         log.Error("Oh, crap!")
	//     })
	//
	//     // 2. If the daemon is doing some IO it is a good idea to limit the
	//     // rate of its execution
	//     b.LimitRate(10, 1 * time.Second)
	//
	//     // 3. If the daemon is also a consumer we need to subscribe for
	//     // topics that would be consumed by the daemon
	//     b.Subscribe("ProductPriceUpdates", func(p PriceUpdate) {
	// 	       log.Printf("Price for %q is now $%.2f", p.Product, p.Amount)
	//     })
	// }
	Startup()

	// Shutdown implementation should clean up all daemon related stuff:
	// close channels, process the last batch of items, etc.
	Shutdown()

	// String returns the name of a daemon.
	String() string
	// contains filtered or unexported methods
}

Daemon is the interface that contains a set of methods required to be implemented in order to be treated as a daemon.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

Logger is the interface that implements minimal logging functions.

type PanicHandler

type PanicHandler func(error)

PanicHandler is a function that handles panics. Duh!

type Shezmu

type Shezmu struct {
	DaemonStats stats.Publisher
	Logger      Logger
	NumWorkers  int
	// contains filtered or unexported fields
}

Shezmu is the master daemon.

func Summon

func Summon() *Shezmu

Summon creates a new instance of Shezmu.

func (*Shezmu) AddDaemon

func (s *Shezmu) AddDaemon(d Daemon)

AddDaemon adds a new daemon.

func (*Shezmu) ClearDaemons

func (s *Shezmu) ClearDaemons()

ClearDaemons clears the list of added daemons. StopDaemons() function MUST be called before calling ClearDaemons().

func (*Shezmu) HandleSignals

func (s *Shezmu) HandleSignals()

func (*Shezmu) StartDaemons

func (s *Shezmu) StartDaemons()

StartDaemons starts all registered daemons.

func (*Shezmu) StopDaemons

func (s *Shezmu) StopDaemons()

StopDaemons stops all running daemons.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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