diff --git a/commands/pilosa-cruncher/cruncher.go b/commands/pilosa-cruncher/cruncher.go index a94dd842f..0efe20441 100644 --- a/commands/pilosa-cruncher/cruncher.go +++ b/commands/pilosa-cruncher/cruncher.go @@ -1,7 +1,7 @@ package main import ( - "pilosa/cruncher" + "pilosa/core" "pilosa/db" "flag" "log" @@ -26,6 +26,6 @@ func main() { log.Fatal("Location not valid:", httpLoc) } - cruncher := cruncher.NewCruncher(tcp, http) - cruncher.Run() + service := core.NewService(tcp, http) + service.Run() } diff --git a/core/service.go b/core/service.go index c8914255e..871022d8b 100644 --- a/core/service.go +++ b/core/service.go @@ -290,3 +290,42 @@ func (service *Service) NewListener() chan *db.Message { ch := make(chan *db.Message) return ch } + + +//////////////////////////////////////////////// + + +func (service *Service) Run() { + log.Println("Running service...") + service.SetupEtcd() + //go r.SyncEtcd() + //go service.WatchEtcd() + //go service.HandleConnections() + //service.SetupNetwork() + //go service.Serve() + //go service.HandleInbox() + //go service.ServeHTTP() + go service.MetaWatcher() + + sigterm, sighup := service.GetSignals() + for { + select { + case <- sighup: + log.Println("SIGHUP! Reloading configuration...") + // TODO: reload configuration + case <- sigterm: + log.Println("SIGTERM! Cleaning up...") + service.Stop() + return + } + } +} + +func (service *Service) HandleInbox() { + for { + select { + case message := <-service.Inbox: + log.Println("process", message) + } + } +} diff --git a/cruncher/cruncher.go b/cruncher/cruncher.go deleted file mode 100644 index 980699f63..000000000 --- a/cruncher/cruncher.go +++ /dev/null @@ -1,56 +0,0 @@ -package cruncher - -import ( - "pilosa/core" - "pilosa/db" - "log" -) - -type Cruncher struct { - core.Service -} - -func (c *Cruncher) Init() { - log.Println("Initializing cruncher...") -} - -func (c *Cruncher) Run() { - log.Println("Running cruncher...") - c.SetupEtcd() - //go r.SyncEtcd() - //go c.WatchEtcd() - //go c.HandleConnections() - //c.SetupNetwork() - //go c.Serve() - //go c.HandleInbox() - //go c.ServeHTTP() - go c.MetaWatcher() - - sigterm, sighup := c.GetSignals() - for { - select { - case <- sighup: - log.Println("SIGHUP! Reloading configuration...") - // TODO: reload configuration - case <- sigterm: - log.Println("SIGTERM! Cleaning up...") - c.Stop() - return - } - } -} - -func NewCruncher(tcp, http *db.Location) *Cruncher { - service := core.NewService(tcp, http) - cruncher := Cruncher{*service} - return &cruncher -} - -func (c *Cruncher) HandleInbox() { - for { - select { - case message := <-c.Inbox: - log.Println("process", message) - } - } -}