forked from BotBotMe/botbot-bot
/
main.go
56 lines (42 loc) · 1011 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
_ "expvar"
"flag"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/BotBotMe/botbot-bot/common"
"github.com/golang/glog"
_ "net/http/pprof"
)
const (
// Prefix of Redis channel to listen for messages on
LISTEN_QUEUE_PREFIX = "bot"
)
func main() {
flag.Parse()
glog.Infoln("START. Use 'botbot -help' for command line options.")
storage := common.NewPostgresStorage()
defer storage.Close()
queue := common.NewRedisQueue()
botbot := NewBotBot(storage, queue)
// Listen for incoming commands
go botbot.listen(LISTEN_QUEUE_PREFIX)
// Start the main loop
go botbot.mainLoop()
// Start and http server to serve the stats from expvar
log.Fatal(http.ListenAndServe(":3030", nil))
// Trap stop signal (Ctrl-C, kill) to exit
kill := make(chan os.Signal)
signal.Notify(kill, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
// Wait for stop signal
for {
<-kill
glog.Infoln("Graceful shutdown")
botbot.shutdown()
break
}
glog.Infoln("Bye")
}