Skip to content

Commit

Permalink
简化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
oldfritter committed Sep 23, 2019
1 parent 840927f commit f3e207d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
27 changes: 2 additions & 25 deletions schedules/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
utils.InitRedisPools()
utils.InitializeAmqpConfig()

initializers.InitCacheData()
initializers.LoadCacheData()

InitSchedule()

Expand All @@ -34,37 +34,14 @@ func main() {
fmt.Println(err)
}

go func() {
channel, err := utils.RabbitMqConnect.Channel()
if err != nil {
fmt.Errorf("Channel: %s", err)
}
channel.ExchangeDeclare("panama.fanout", "fanout", true, false, false, false, nil)
queue, err := channel.QueueDeclare("", true, false, false, false, nil)
if err != nil {
return
}
QueueName = queue.Name
channel.QueueBind(queue.Name, QueueName, "panama.fanout", false, nil)
msgs, _ := channel.Consume(queue.Name, "", true, false, false, false, nil)
for _ = range msgs {
initializers.InitCacheData()
}
return
}()

quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
channel, err := utils.RabbitMqConnect.Channel()
if err != nil {
fmt.Errorf("Channel: %s", err)
}
channel.QueueDelete(QueueName, false, false, false)
closeResource()
}

func closeResource() {
initializers.DeleteListeQueue()
utils.CloseAmqpConnection()
utils.CloseRedisPools()
utils.CloseMainDB()
Expand Down
3 changes: 3 additions & 0 deletions workers/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"

envConfig "github.com/oldfritter/goDCE/config"
"github.com/oldfritter/goDCE/initializers"
"github.com/oldfritter/goDCE/models"
"github.com/oldfritter/goDCE/utils"
"github.com/oldfritter/goDCE/workers/sneakerWorkers"
Expand All @@ -33,6 +34,7 @@ func initialize() {
models.AutoMigrations()
utils.InitRedisPools()
utils.InitializeAmqpConfig()
initializers.LoadCacheData()

err := ioutil.WriteFile("pids/workers.pid", []byte(strconv.Itoa(os.Getpid())), 0644)
if err != nil {
Expand All @@ -41,6 +43,7 @@ func initialize() {
}

func closeResource() {
initializers.DeleteListeQueue()
utils.CloseAmqpConnection()
utils.CloseRedisPools()
utils.CloseMainDB()
Expand Down

0 comments on commit f3e207d

Please sign in to comment.