| 202 | } |
| 203 | |
| 204 | func main() { |
| 205 | grpc.EnableTracing = false |
| 206 | |
| 207 | flag.Parse() |
| 208 | lis, err := net.Listen("tcp", ":"+strconv.Itoa(*driverPort)) |
| 209 | if err != nil { |
| 210 | logger.Fatalf("failed to listen: %v", err) |
| 211 | } |
| 212 | logger.Infof("worker listening at port %v", *driverPort) |
| 213 | |
| 214 | s := grpc.NewServer() |
| 215 | stop := make(chan bool) |
| 216 | testgrpc.RegisterWorkerServiceServer(s, &workerServer{ |
| 217 | stop: stop, |
| 218 | serverPort: *serverPort, |
| 219 | }) |
| 220 | |
| 221 | go func() { |
| 222 | <-stop |
| 223 | // Wait for 1 second before stopping the server to make sure the return value of QuitWorker is sent to client. |
| 224 | // TODO revise this once server graceful stop is supported in gRPC. |
| 225 | time.Sleep(time.Second) |
| 226 | s.Stop() |
| 227 | }() |
| 228 | |
| 229 | runtime.SetBlockProfileRate(*blockProfRate) |
| 230 | |
| 231 | if *pprofPort >= 0 { |
| 232 | go func() { |
| 233 | logger.Infoln("Starting pprof server on port " + strconv.Itoa(*pprofPort)) |
| 234 | logger.Infoln(http.ListenAndServe("localhost:"+strconv.Itoa(*pprofPort), nil)) |
| 235 | }() |
| 236 | } |
| 237 | |
| 238 | s.Serve(lis) |
| 239 | } |