@@ -81,22 +81,21 @@ func main() {
8181 poolInstance .SetBusyNodeDuration (busyNodeDuration )
8282 poolInstance .SetReservedNodeDuration (reservedNodeDuration )
8383
84- //todo: сделать конфиг для пула, вынести duration туда
85- poolMetricsSender := poolMetrics .NewSender (statsdClient , poolInstance , time .Second * 1 ) //todo: вынести в конфиг
84+ poolMetricsSender := poolMetrics .NewSender (statsdClient , poolInstance , time .Second * 1 ) // todo: move to config
8685 go poolMetricsSender .SendAll ()
8786
8887 go func () {
8988 for {
9089 poolInstance .FixNodeStatuses ()
91- time .Sleep (time .Minute * 5 ) // todo: вынести в конфиг
90+ time .Sleep (time .Minute * 5 ) // todo: move to config
9291 }
9392 }()
9493
9594 m := middleware .NewLogMiddleware (statsdClient )
9695 http .Handle ("/wd/hub/session" , m .Log (& handlers.CreateSession {Pool : poolInstance , ClientFactory : clientFactory })) //selenium
9796 http .Handle ("/session" , m .Log (& handlers.CreateSession {Pool : poolInstance , ClientFactory : clientFactory })) //wda
9897 http .Handle ("/grid/register" , m .Log (& handlers.RegisterNode {Pool : poolInstance }))
99- http .Handle ("/grid/api/proxy" , & handlers.ApiProxy {Pool : poolInstance })
98+ http .Handle ("/grid/api/proxy" , & handlers.APIProxy {Pool : poolInstance })
10099 http .HandleFunc ("/_info" , heartbeat )
101100 http .Handle ("/" , m .Log (& handlers.UseSession {Pool : poolInstance }))
102101
@@ -118,15 +117,21 @@ func main() {
118117
119118 log .Info ("Shutting down the server..." )
120119
121- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Minute ) // todo: вынести в конфиг
120+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Minute ) // todo: move to config
122121 defer cancel ()
123- server .Shutdown (ctx )
122+ err = server .Shutdown (ctx )
123+ if err != nil {
124+ log .Fatalf ("graceful shutdown, %v" , err )
125+ }
124126
125127 log .Info ("Server gracefully stopped" )
126128}
127129
128130func heartbeat (w http.ResponseWriter , r * http.Request ) {
129131 w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
130132 w .WriteHeader (http .StatusOK )
131- w .Write ([]byte (`{"result": {"ok": true}}` ))
133+ _ , err := w .Write ([]byte (`{"result": {"ok": true}}` ))
134+ if err != nil {
135+ log .Errorf ("write response, %v" , err )
136+ }
132137}
0 commit comments