main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/workflow/conf"
  8. "go-common/app/job/main/workflow/http"
  9. "go-common/app/job/main/workflow/service"
  10. "go-common/library/log"
  11. "go-common/library/queue/databus/report"
  12. )
  13. var (
  14. srv *service.Service
  15. )
  16. func main() {
  17. flag.Parse()
  18. report.InitManager(nil)
  19. if err := conf.Init(); err != nil {
  20. log.Error("conf.Init() error(%v)", err)
  21. panic(err)
  22. }
  23. log.Init(conf.Conf.Log)
  24. defer log.Close()
  25. log.Info("workflow-job start")
  26. srv = service.New(conf.Conf)
  27. http.Init(conf.Conf, srv)
  28. signalHandler()
  29. }
  30. func signalHandler() {
  31. var (
  32. err error
  33. ch = make(chan os.Signal, 1)
  34. )
  35. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  36. for {
  37. si := <-ch
  38. switch si {
  39. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  40. log.Info("get a signal %s, stop the consume process", si.String())
  41. if err = srv.Close(); err != nil {
  42. log.Error("srv close consumer error(%v)", err)
  43. }
  44. return
  45. case syscall.SIGHUP:
  46. default:
  47. return
  48. }
  49. }
  50. }