cloud-game/cmd/overworker/main.go
Sadlil Rhythom 0e17092acb Refactor of cloud game overlord and overworker (#70)
* Introduce Makefile and go vendor directory for faster build

* WIP: Refactor cloud-game codebase with spliting overlord and worker binary

* Fix all issues and have a running build

* Complete first version of refactor
2019-09-12 03:35:21 +08:00

43 lines
844 B
Go

package main
import (
"context"
"math/rand"
"os"
"os/signal"
"time"
"github.com/giongto35/cloud-game/pkg/util/logging"
"github.com/giongto35/cloud-game/pkg/worker"
"github.com/golang/glog"
"github.com/spf13/pflag"
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
cfg := worker.NewDefaultConfig()
cfg.AddFlags(pflag.CommandLine)
logging.Init()
defer logging.Flush()
ctx, cancelCtx := context.WithCancel(context.Background())
glog.Infof("Initializing worker server")
glog.V(4).Infof("Worker configs %v", cfg)
o := worker.New(ctx, cfg)
if err := o.Run(); err != nil {
glog.Errorf("Failed to run worker, reason %v", err)
os.Exit(1)
}
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
select {
case <-stop:
glog.Infoln("Received SIGTERM, Quiting Worker")
o.Shutdown()
cancelCtx()
}
}