63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"git.loafle.net/commons/configuration-go"
|
|
"git.loafle.net/commons/logging-go"
|
|
"git.loafle.net/overflow/consumer_metric/config"
|
|
"git.loafle.net/overflow/consumer_metric/consumer"
|
|
)
|
|
|
|
var (
|
|
configDir *string
|
|
)
|
|
|
|
func init() {
|
|
configDir = flag.String("config-dir", "./", "Config directory")
|
|
logConfigPath := flag.String("log-config", "", "logging config path")
|
|
flag.Parse()
|
|
|
|
logging.InitializeLogger(*logConfigPath)
|
|
}
|
|
|
|
func main() {
|
|
defer logging.Logger().Sync()
|
|
|
|
_config := &config.Config{}
|
|
configuration.SetConfigPath(*configDir)
|
|
if err := configuration.Load(_config, "config.json"); nil != err {
|
|
logging.Logger().Panic(err)
|
|
}
|
|
|
|
c := consumer.New(_config)
|
|
|
|
err := c.Start()
|
|
if nil != err {
|
|
log.Printf("err: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
interrupt := make(chan os.Signal, 1)
|
|
signal.Notify(interrupt,
|
|
syscall.SIGKILL,
|
|
syscall.SIGSTOP,
|
|
syscall.SIGHUP,
|
|
syscall.SIGINT,
|
|
syscall.SIGTERM,
|
|
syscall.SIGQUIT)
|
|
|
|
<-interrupt
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
if err := c.Stop(ctx); err != nil {
|
|
logging.Logger().Errorf("error: %v", err)
|
|
}
|
|
}
|