Rename to Shezmu
This commit is contained in:
parent
c5f995035a
commit
bb750bf727
@ -1,6 +1,6 @@
|
|||||||
# Satan
|
# Shezmu
|
||||||
|
|
||||||
Satan is a daemon execution platform for Go apps.
|
Shezmu is a daemon execution platform for Go apps.
|
||||||
|
|
||||||
* What is a daemon execution platform?
|
* What is a daemon execution platform?
|
||||||
* What does it provide?
|
* What does it provide?
|
||||||
|
@ -5,7 +5,7 @@ into the functions' first argument. Its main purpose is to hide common
|
|||||||
unmarshalling code from each function implementation thus reducing
|
unmarshalling code from each function implementation thus reducing
|
||||||
boilerplate and making package interaction code sexier.
|
boilerplate and making package interaction code sexier.
|
||||||
|
|
||||||
[Documentation](https://godoc.org/github.com/localhots/satan/caller)
|
[Documentation](https://godoc.org/github.com/localhots/shezmu/caller)
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"github.com/localhots/satan/caller"
|
"github.com/localhots/shezmu/caller"
|
||||||
"github.com/path/to/package/messenger"
|
"github.com/path/to/package/messenger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ Support code:
|
|||||||
package messenger
|
package messenger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/localhots/satan/caller"
|
"github.com/localhots/shezmu/caller"
|
||||||
)
|
)
|
||||||
|
|
||||||
type item struct {
|
type item struct {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package satan
|
package shezmu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/juju/ratelimit"
|
"github.com/juju/ratelimit"
|
||||||
"github.com/localhots/satan/caller"
|
"github.com/localhots/shezmu/caller"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Daemon is the interface that contains a set of methods required to be
|
// Daemon is the interface that contains a set of methods required to be
|
||||||
@ -155,14 +155,14 @@ func (d *BaseDaemon) Continue() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log logs values using satan.Logger.Println function.
|
// Log logs values using shezmu.Logger.Println function.
|
||||||
func (d *BaseDaemon) Log(v ...interface{}) {
|
func (d *BaseDaemon) Log(v ...interface{}) {
|
||||||
if d.logger != nil {
|
if d.logger != nil {
|
||||||
d.logger.Println(v...)
|
d.logger.Println(v...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logf logs values using satan.Logger.Printf function.
|
// Logf logs values using shezmu.Logger.Printf function.
|
||||||
func (d *BaseDaemon) Logf(format string, v ...interface{}) {
|
func (d *BaseDaemon) Logf(format string, v ...interface{}) {
|
||||||
if d.logger != nil {
|
if d.logger != nil {
|
||||||
d.logger.Printf(format, v...)
|
d.logger.Printf(format, v...)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "satan",
|
"name": "shezmu",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "0.14.0",
|
"react": "0.14.0",
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# Satan example application
|
# Shezmu example application
|
||||||
|
|
||||||
Describe the app here.
|
Describe the app here.
|
||||||
|
@ -4,12 +4,12 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/localhots/satan"
|
"github.com/localhots/shezmu"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NumberPrinter is a daemon that prints numbers once in a while.
|
// NumberPrinter is a daemon that prints numbers once in a while.
|
||||||
type NumberPrinter struct {
|
type NumberPrinter struct {
|
||||||
satan.BaseDaemon
|
shezmu.BaseDaemon
|
||||||
}
|
}
|
||||||
|
|
||||||
// Startup sets up panic handler and starts enqueuing number printing jobs.
|
// Startup sets up panic handler and starts enqueuing number printing jobs.
|
||||||
@ -33,7 +33,7 @@ func (n *NumberPrinter) generateNumbers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NumberPrinter) makeActor(num int) satan.Actor {
|
func (n *NumberPrinter) makeActor(num int) shezmu.Actor {
|
||||||
return func() {
|
return func() {
|
||||||
n.Log("Number printer says:", num)
|
n.Log("Number printer says:", num)
|
||||||
|
|
||||||
|
@ -3,12 +3,12 @@ package daemons
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/localhots/satan"
|
"github.com/localhots/shezmu"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PriceConsumer consumes price update messages and prints them to the console.
|
// PriceConsumer consumes price update messages and prints them to the console.
|
||||||
type PriceConsumer struct {
|
type PriceConsumer struct {
|
||||||
satan.BaseDaemon
|
shezmu.BaseDaemon
|
||||||
}
|
}
|
||||||
|
|
||||||
// PriceUpdate describes a price update message.
|
// PriceUpdate describes a price update message.
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Shopify/sarama"
|
"github.com/Shopify/sarama"
|
||||||
"github.com/localhots/satan"
|
"github.com/localhots/shezmu"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConsumerState contains data that is required to create a Kafka consumer.
|
// ConsumerState contains data that is required to create a Kafka consumer.
|
||||||
@ -18,10 +18,10 @@ type ConsumerState struct {
|
|||||||
Offset int64 `json:"offset"`
|
Offset int64 `json:"offset"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscriber is a dummy structure that implements satan.Subscriber interface.
|
// Subscriber is a dummy structure that implements shezmu.Subscriber interface.
|
||||||
type Subscriber struct{}
|
type Subscriber struct{}
|
||||||
|
|
||||||
// Stream is an implementation of satan.Stremer for Kafka messaging queue.
|
// Stream is an implementation of shezmu.Stremer for Kafka messaging queue.
|
||||||
type Stream struct {
|
type Stream struct {
|
||||||
messages chan []byte
|
messages chan []byte
|
||||||
shutdown chan struct{}
|
shutdown chan struct{}
|
||||||
@ -44,7 +44,7 @@ func Initialize(brokers []string) {
|
|||||||
defer log.Println("Kafka is initialized")
|
defer log.Println("Kafka is initialized")
|
||||||
|
|
||||||
conf := sarama.NewConfig()
|
conf := sarama.NewConfig()
|
||||||
conf.ClientID = "Satan Example"
|
conf.ClientID = "Shezmu Example"
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if kafkaClient, err = sarama.NewClient(brokers, conf); err != nil {
|
if kafkaClient, err = sarama.NewClient(brokers, conf); err != nil {
|
||||||
@ -70,8 +70,8 @@ func Shutdown() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe creates a satan.Streamer implementation for Kafka messaging queue.
|
// Subscribe creates a shezmu.Streamer implementation for Kafka messaging queue.
|
||||||
func (s Subscriber) Subscribe(consumer, topic string) satan.Streamer {
|
func (s Subscriber) Subscribe(consumer, topic string) shezmu.Streamer {
|
||||||
c, ok := consumers[consumer]
|
c, ok := consumers[consumer]
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Errorf("Consumer %q has no config", consumer))
|
panic(fmt.Errorf("Consumer %q has no config", consumer))
|
||||||
|
@ -7,11 +7,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/localhots/satan"
|
"github.com/localhots/shezmu"
|
||||||
"github.com/localhots/satan/example/daemons"
|
"github.com/localhots/shezmu/example/daemons"
|
||||||
"github.com/localhots/satan/example/kafka"
|
"github.com/localhots/shezmu/example/kafka"
|
||||||
"github.com/localhots/satan/server"
|
"github.com/localhots/shezmu/server"
|
||||||
"github.com/localhots/satan/stats"
|
"github.com/localhots/shezmu/stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -30,7 +30,7 @@ func main() {
|
|||||||
server := server.New(6464, statsServer)
|
server := server.New(6464, statsServer)
|
||||||
server.Start()
|
server.Start()
|
||||||
|
|
||||||
s := satan.Summon()
|
s := shezmu.Summon()
|
||||||
s.Subscriber = kafka.Subscriber{}
|
s.Subscriber = kafka.Subscriber{}
|
||||||
s.DaemonStats = stats.NewGroup(statsLogger, statsServer)
|
s.DaemonStats = stats.NewGroup(statsLogger, statsServer)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/localhots/satan/stats"
|
"github.com/localhots/shezmu/stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package satan
|
package shezmu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -8,11 +8,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/localhots/satan/stats"
|
"github.com/localhots/shezmu/stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Satan is the master daemon.
|
// Shezmu is the master daemon.
|
||||||
type Satan struct {
|
type Shezmu struct {
|
||||||
Subscriber Subscriber
|
Subscriber Subscriber
|
||||||
Publisher Publisher
|
Publisher Publisher
|
||||||
DaemonStats stats.Publisher
|
DaemonStats stats.Publisher
|
||||||
@ -71,9 +71,9 @@ const (
|
|||||||
DefaultNumWorkers = 100
|
DefaultNumWorkers = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
// Summon creates a new instance of Satan.
|
// Summon creates a new instance of Shezmu.
|
||||||
func Summon() *Satan {
|
func Summon() *Shezmu {
|
||||||
return &Satan{
|
return &Shezmu{
|
||||||
DaemonStats: &stats.Void{},
|
DaemonStats: &stats.Void{},
|
||||||
Logger: log.New(os.Stdout, "[daemons] ", log.LstdFlags),
|
Logger: log.New(os.Stdout, "[daemons] ", log.LstdFlags),
|
||||||
NumWorkers: DefaultNumWorkers,
|
NumWorkers: DefaultNumWorkers,
|
||||||
@ -85,7 +85,7 @@ func Summon() *Satan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddDaemon adds a new daemon.
|
// AddDaemon adds a new daemon.
|
||||||
func (s *Satan) AddDaemon(d Daemon) {
|
func (s *Shezmu) AddDaemon(d Daemon) {
|
||||||
base := d.base()
|
base := d.base()
|
||||||
base.self = d
|
base.self = d
|
||||||
base.subscriber = s.Subscriber
|
base.subscriber = s.Subscriber
|
||||||
@ -99,7 +99,7 @@ func (s *Satan) AddDaemon(d Daemon) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StartDaemons starts all registered daemons.
|
// StartDaemons starts all registered daemons.
|
||||||
func (s *Satan) StartDaemons() {
|
func (s *Shezmu) StartDaemons() {
|
||||||
s.Logger.Printf("Starting %d workers", s.NumWorkers)
|
s.Logger.Printf("Starting %d workers", s.NumWorkers)
|
||||||
for i := 0; i < s.NumWorkers; i++ {
|
for i := 0; i < s.NumWorkers; i++ {
|
||||||
go s.runWorker()
|
go s.runWorker()
|
||||||
@ -107,7 +107,7 @@ func (s *Satan) StartDaemons() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StopDaemons stops all running daemons.
|
// StopDaemons stops all running daemons.
|
||||||
func (s *Satan) StopDaemons() {
|
func (s *Shezmu) StopDaemons() {
|
||||||
close(s.shutdownSystem)
|
close(s.shutdownSystem)
|
||||||
for _, d := range s.daemons {
|
for _, d := range s.daemons {
|
||||||
d.Shutdown()
|
d.Shutdown()
|
||||||
@ -121,7 +121,7 @@ func (s *Satan) StopDaemons() {
|
|||||||
fmt.Println(s.runtimeStats.Fetch(stats.Latency))
|
fmt.Println(s.runtimeStats.Fetch(stats.Latency))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Satan) runWorker() {
|
func (s *Shezmu) runWorker() {
|
||||||
s.wgWorkers.Add(1)
|
s.wgWorkers.Add(1)
|
||||||
defer s.wgWorkers.Done()
|
defer s.wgWorkers.Done()
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -142,7 +142,7 @@ func (s *Satan) runWorker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Satan) processTask(t *task) {
|
func (s *Shezmu) processTask(t *task) {
|
||||||
dur := time.Now().Sub(t.createdAt)
|
dur := time.Now().Sub(t.createdAt)
|
||||||
s.runtimeStats.Add(stats.Latency, dur)
|
s.runtimeStats.Add(stats.Latency, dur)
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ func (s *Satan) processTask(t *task) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Satan) processSystemTask(t *task) {
|
func (s *Shezmu) processSystemTask(t *task) {
|
||||||
// Abort starting a system task if shutdown was already called. Otherwise
|
// Abort starting a system task if shutdown was already called. Otherwise
|
||||||
// incrementing a wait group counter will cause a panic. This should be an
|
// incrementing a wait group counter will cause a panic. This should be an
|
||||||
// extremely rare scenario when a system task crashes and tries to restart
|
// extremely rare scenario when a system task crashes and tries to restart
|
||||||
@ -182,7 +182,7 @@ func (s *Satan) processSystemTask(t *task) {
|
|||||||
t.actor() // <--- ACTION STARTS HERE
|
t.actor() // <--- ACTION STARTS HERE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Satan) processGeneralTask(t *task) {
|
func (s *Shezmu) processGeneralTask(t *task) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
s.DaemonStats.Error(t.daemon.base().String())
|
s.DaemonStats.Error(t.daemon.base().String())
|
@ -7,7 +7,7 @@ def main():
|
|||||||
source = open(".gitmodules").read()
|
source = open(".gitmodules").read()
|
||||||
paths = re.findall(r"path = (.*)", source)
|
paths = re.findall(r"path = (.*)", source)
|
||||||
|
|
||||||
print("github.com/localhots/satan {}".format(path_sha1(".")))
|
print("github.com/localhots/shezmu {}".format(path_sha1(".")))
|
||||||
for path in paths:
|
for path in paths:
|
||||||
print("{} {}".format(path[7:], path_sha1(path)))
|
print("{} {}".format(path[7:], path_sha1(path)))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user