// Daemon will run and maintain skynet services. // // Daemon will run the "SkynetDeployment" service, which can be used // to remotely spawn new services on the host. func main() { si := skynet.NewServiceInfo("SkynetDaemon", "2.0.0") deployment := NewSkynetDaemon() s := service.CreateService(deployment, si) deployment.Service = s // handle panic so that we remove ourselves from the pool in case of catastrophic failure defer func() { s.Shutdown() deployment.closeStateFile() if err := recover(); err != nil { e := err.(error) log.Fatal("Unrecovered error occured: " + e.Error()) } }() // Collect Host metrics statTicker := time.Tick((5 * time.Second)) go func() { for _ = range statTicker { deployment.updateHostStats(si.ServiceAddr.IPAddress) } }() // If we pass false here service will not be Registered // we could do other work/tasks by implementing the Started method and calling Register() when we're ready s.Start().Wait() }
func TestPoolClose(t *testing.T) { si := skynet.NewServiceInfo("TestService", "1.0.0") si.Registered = true si.ServiceAddr.IPAddress = "127.0.0.1" si.ServiceAddr.Port = 9000 p := NewPool() p.AddInstance(*si) p.Close() if len(p.servicePools) > 0 { t.Fatal("Close() did not close all service pools") } }
func main() { testService := NewTestService() serviceInfo := skynet.NewServiceInfo("TestService", "1.0.0") service := service.CreateService(testService, serviceInfo) // handle panic so that we remove ourselves from the pool in case // of catastrophic failure defer func() { service.Shutdown() if err := recover(); err != nil { log.Panic("Unrecovered error occured: ", err) } }() waiter := service.Start() // waiting on the sync.WaitGroup returned by service.Start() will // wait for the service to finish running. waiter.Wait() }
func serviceInfo(registered bool) skynet.ServiceInfo { si := skynet.NewServiceInfo(nil) si.Registered = registered return si }
func serviceInfo() *skynet.ServiceInfo { si := skynet.NewServiceInfo("TestService", "1.0.0") si.Registered = true return si }