open-match.dev/open-match@v1.8.1/examples/scale/evaluator/evaluator.go (about) 1 // 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package evaluator 15 16 import ( 17 "fmt" 18 "net" 19 20 "github.com/sirupsen/logrus" 21 "google.golang.org/grpc" 22 23 "open-match.dev/open-match/pkg/pb" 24 25 utilTesting "open-match.dev/open-match/internal/util/testing" 26 27 "open-match.dev/open-match/examples/scale/scenarios" 28 ) 29 30 var ( 31 logger = logrus.WithFields(logrus.Fields{ 32 "app": "openmatch", 33 "component": "scale.evaluator", 34 }) 35 ) 36 37 // Run triggers execution of an evaluator. 38 func Run() { 39 activeScenario := scenarios.ActiveScenario 40 41 server := grpc.NewServer(utilTesting.NewGRPCServerOptions(logger)...) 42 pb.RegisterEvaluatorServer(server, activeScenario.Evaluator) 43 ln, err := net.Listen("tcp", fmt.Sprintf(":%d", 50508)) 44 if err != nil { 45 logger.WithFields(logrus.Fields{ 46 "error": err.Error(), 47 "port": 50508, 48 }).Fatal("net.Listen() error") 49 } 50 51 logger.WithFields(logrus.Fields{ 52 "port": 50508, 53 }).Info("TCP net listener initialized") 54 55 logger.Info("Serving gRPC endpoint") 56 err = server.Serve(ln) 57 if err != nil { 58 logger.WithFields(logrus.Fields{ 59 "error": err.Error(), 60 }).Fatal("gRPC serve() error") 61 } 62 }