Handle no config situation for workers (#253)

(experimental feature)

Before a worker can start, it should have a configuration file. In case if such a file is not found it may request configuration from the coordinator to which it connected.

Added example logic if a worker is needed to be blocked until a successful packet exchange with a coordinator is being made.

* Add error return for config loader

* Add config loaded flag to worker

* Add zone flag

* Add a custom mutex lock with timout

* Refactor worker runtime

* Refactor internal api

* Extract monitoring server config

* Extract worker HTTP(S) server

* Add generic sub-server interface

* Add internal coordinator API

* Add internal routes and handlers to worker

* Add internal worker API

* Refactor worker run

* Migrate serverId call to new API

* Add packet handler to cws

* Extract handlers for internal worker routes in coordinator

* Pass worker to the worker internal heandlers

* Cleanup worker handlers in coordinator

* Add closeRoom packet handler to the API

* Add GetRoom packet handler to the API

* Add RegisterRoom packet handler to the API

* Add IceCandidate packet handler to the API (internal and browser)

* Add Heartbeat packet handler to the API (internal and browser)

* Rename worker routes init function

* Extract worker/coordinator internal ws handlers

* Update timed locker

* Allow sequential timed locks

* Add config request from workers

* Add nil check for the route registration functions
This commit is contained in:
sergystepanov 2021-01-03 21:23:55 +03:00 committed by Sergey Stepanov
parent 6cee6061b6
commit 980a97a526
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
31 changed files with 1134 additions and 862 deletions

View file

@ -16,9 +16,11 @@ import (
flag "github.com/spf13/pflag"
)
func run() {
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
func run() {
conf := config.NewConfig()
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
conf.ParseFlags()
@ -28,20 +30,17 @@ func run() {
ctx, cancelCtx := context.WithCancel(context.Background())
glog.Infof("Initializing worker server")
glog.V(4).Infof("Worker configs %v", conf)
o := worker.New(ctx, conf)
if err := o.Run(); err != nil {
glog.Errorf("Failed to run worker, reason %v", err)
os.Exit(1)
}
glog.V(4).Info("[worker] Initialization")
glog.V(4).Infof("[worker] Local configuration %+v", conf)
wrk := worker.New(ctx, conf)
wrk.Run()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
select {
case <-stop:
glog.Infoln("Received SIGTERM, Quiting Worker")
o.Shutdown()
glog.V(4).Info("[worker] Shutting down")
wrk.Shutdown()
cancelCtx()
}
}