shezmu

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

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

Go to latest
Published: Jul 19, 2016 License: MIT Imports: 11 Imported by: 15

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) Publish

func (d *BaseDaemon) Publish(topic string, msg []byte, meta interface{})

Publish sends a message to the publisher.

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) String

func (d *BaseDaemon) String() string

String returns the name of the Deamon unerlying struct.

func (*BaseDaemon) Subscribe

func (d *BaseDaemon) Subscribe(topic string, fun interface{})

Subscribe subscriasdsdfsdgdfgdfsg sdgsdfg sdfgs dfgdfgdfg.

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(interface{})

PanicHandler is a function that handles panics. Duh!

type Publisher

type Publisher interface {
	Publish(topic string, msg []byte, meta interface{})
	Close()
}

Publisher is the interface that wraps message publishers. Error handling should be provided by the implementation. Feel free to panic.

type Shezmu

type Shezmu struct {
	Subscriber  Subscriber
	Publisher   Publisher
	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) StartDaemons

func (s *Shezmu) StartDaemons()

StartDaemons starts all registered daemons.

func (*Shezmu) StopDaemons

func (s *Shezmu) StopDaemons()

StopDaemons stops all running daemons.

type Streamer

type Streamer interface {
	Messages() <-chan []byte
	Close()
}

Streamer is the interface that wraps message consumers. Error handling should be provided by the implementation. Feel free to panic.

type Subscriber

type Subscriber interface {
	Subscribe(consumerName, topic string) Streamer
}

Subscriber is the interface that is used by daemons to subscribe to messages.

Directories

Path Synopsis
Package caller is used to dynamically call functions with data unmarshalled into the functions' first argument.
Package caller is used to dynamically call functions with data unmarshalled into the functions' first argument.

Jump to

Keyboard shortcuts

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