本文整理汇总了Golang中github.com/centrifugal/centrifugo/libcentrifugo.Application.Shutdown方法的典型用法代码示例。如果您正苦于以下问题:Golang Application.Shutdown方法的具体用法?Golang Application.Shutdown怎么用?Golang Application.Shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/centrifugal/centrifugo/libcentrifugo.Application
的用法示例。
在下文中一共展示了Application.Shutdown方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleSignals
func handleSignals(app *libcentrifugo.Application) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT, os.Interrupt)
for {
sig := <-sigc
logger.INFO.Println("Signal received:", sig)
switch sig {
case syscall.SIGHUP:
// reload application configuration on SIGHUP
logger.INFO.Println("Reloading configuration")
err := viper.ReadInConfig()
if err != nil {
switch err.(type) {
case viper.ConfigParseError:
logger.CRITICAL.Printf("Error parsing configuration: %s\n", err)
continue
default:
logger.CRITICAL.Println("No config file found")
continue
}
}
setupLogging()
c := newConfig()
app.SetConfig(c)
logger.INFO.Println("Configuration successfully reloaded")
case syscall.SIGINT, os.Interrupt:
logger.INFO.Println("Shutting down")
go time.AfterFunc(10*time.Second, func() {
os.Exit(1)
})
app.Shutdown()
os.Exit(130)
}
}
}
示例2: handleSignals
func handleSignals(app *libcentrifugo.Application) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT, os.Interrupt)
for {
sig := <-sigc
logger.INFO.Println("signal received:", sig)
switch sig {
case syscall.SIGHUP:
// reload application configuration on SIGHUP
// note that you should run checkconfig before reloading configuration
// as Viper exits when encounters parsing errors
logger.INFO.Println("reloading configuration")
err := viper.ReadInConfig()
if err != nil {
logger.CRITICAL.Println("unable to locate config file")
return
}
setupLogging()
c := newConfig()
s := structureFromConfig(nil)
app.SetConfig(c)
app.SetStructure(s)
case syscall.SIGINT, os.Interrupt:
logger.INFO.Println("shutting down")
go time.AfterFunc(5*time.Second, func() {
os.Exit(1)
})
app.Shutdown()
os.Exit(130)
}
}
}