Пример #1
0
func main() {
	f := NewFibonacci()

	config, _ := skynet.GetServiceConfigFromFlags()

	config.Name = "Fibonacci"
	config.Version = "1"
	config.Region = "Jersey"
	var err error
	mlogger, err := skynet.NewMongoLogger("localhost", "skynet", "log", config.UUID)
	clogger := skynet.NewConsoleLogger(os.Stdout)
	config.Log = skynet.NewMultiLogger(mlogger, clogger)
	if err != nil {
		config.Log.Item("Could not connect to mongo db for logging")
	}
	service := service.CreateService(f, config)

	// 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.Println("Unrecovered error occured: ", err)
		}
	}()

	// 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
	waiter := service.Start(true)

	// waiting on the sync.WaitGroup returned by service.Start() will wait for the service to finish running.
	waiter.Wait()
}
Пример #2
0
// Daemon() will run and maintain skynet services.
//
// Daemon() will initially deploy those specified in the file given in the "-config" option
//
// Daemon() will run the "SkynetDeployment" service, which can be used to remotely spawn
// new services on the host.
func Daemon(q *client.Query, argv []string) {

	config, args := skynet.GetServiceConfigFromFlags(argv...)

	config.Name = "SkynetDaemon"
	config.Version = "1"
	config.Region = "Jersey"

	var err error
	mlogger, err := skynet.NewMongoLogger("localhost", "skynet", "log", config.UUID)
	clogger := skynet.NewConsoleLogger(os.Stdout)
	config.Log = skynet.NewMultiLogger(mlogger, clogger)
	if err != nil {
		config.Log.Item("Could not connect to mongo db for logging")
	}

	deployment := &SkynetDaemon{
		Log:      config.Log,
		Services: map[string]*SubService{},
	}

	s := service.CreateService(deployment, config)

	// handle panic so that we remove ourselves from the pool in case of catastrophic failure
	defer func() {
		s.Shutdown()
		if err := recover(); err != nil {
			log.Println("Unrecovered error occured: ", err)
		}
	}()

	if len(args) == 1 {
		err := deployConfig(deployment, args[0])
		if err != nil {
			config.Log.Item(err)
		}
	}

	// 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(true).Wait()
}