code refactor
This commit is contained in:
parent
282aede691
commit
712d0051d9
|
@ -77,5 +77,5 @@ func endingProc() {
|
|||
|
||||
logger.Close()
|
||||
http.Shutdown()
|
||||
fmt.Println("portal stopped successfully")
|
||||
fmt.Println("process stopped successfully")
|
||||
}
|
||||
|
|
|
@ -105,5 +105,5 @@ func endingProc() {
|
|||
|
||||
logger.Close()
|
||||
http.Shutdown()
|
||||
fmt.Println("portal stopped successfully")
|
||||
fmt.Println("process stopped successfully")
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
|
||||
"github.com/streadway/amqp"
|
||||
"github.com/toolkits/pkg/logger"
|
||||
|
||||
"github.com/didi/nightingale/src/modules/rdb/config"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -13,7 +15,14 @@ var (
|
|||
exit = make(chan bool)
|
||||
)
|
||||
|
||||
func Init(url string) {
|
||||
func Init() {
|
||||
if config.Config.RabbitMQ.Enable {
|
||||
dial(config.Config.RabbitMQ.Addr)
|
||||
go Consume(config.Config.RabbitMQ.Addr, config.Config.RabbitMQ.Queue)
|
||||
}
|
||||
}
|
||||
|
||||
func dial(url string) {
|
||||
var err error
|
||||
conn, err = amqp.Dial(url)
|
||||
if err != nil {
|
||||
|
@ -70,6 +79,8 @@ func close() {
|
|||
}
|
||||
|
||||
func Shutdown() {
|
||||
conn.Close()
|
||||
exit <- true
|
||||
if config.Config.RabbitMQ.Enable {
|
||||
conn.Close()
|
||||
exit <- true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,10 +68,7 @@ func main() {
|
|||
cron.InitWorker()
|
||||
|
||||
// 初始化 rabbitmq 处理部分异步逻辑
|
||||
if config.Config.RabbitMQ.Enable {
|
||||
rabbitmq.Init(config.Config.RabbitMQ.Addr)
|
||||
go rabbitmq.Consume(config.Config.RabbitMQ.Addr, config.Config.RabbitMQ.Queue)
|
||||
}
|
||||
rabbitmq.Init()
|
||||
|
||||
go cron.ConsumeMail()
|
||||
go cron.ConsumeSms()
|
||||
|
@ -101,10 +98,7 @@ func endingProc() {
|
|||
logger.Close()
|
||||
http.Shutdown()
|
||||
redisc.CloseRedis()
|
||||
rabbitmq.Shutdown()
|
||||
|
||||
if config.Config.RabbitMQ.Enable {
|
||||
rabbitmq.Shutdown()
|
||||
}
|
||||
|
||||
fmt.Println("stopped successfully")
|
||||
fmt.Println("process stopped successfully")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue