allow graceful shutdown
This commit is contained in:
parent
f96698b54d
commit
3153ab9ae3
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -200,11 +201,28 @@ var serveDealStatsCmd = &cli.Command{
|
|||||||
|
|
||||||
dss := &dealStatsServer{api}
|
dss := &dealStatsServer{api}
|
||||||
|
|
||||||
http.HandleFunc("/api/storagedeal/count", dss.handleStorageDealCount)
|
mux := &http.ServeMux{}
|
||||||
http.HandleFunc("/api/storagedeal/averagesize", dss.handleStorageDealAverageSize)
|
mux.HandleFunc("/api/storagedeal/count", dss.handleStorageDealCount)
|
||||||
http.HandleFunc("/api/storagedeal/totalreal", dss.handleStorageDealTotalReal)
|
mux.HandleFunc("/api/storagedeal/averagesize", dss.handleStorageDealAverageSize)
|
||||||
http.HandleFunc("/api/storagedeal/clientstats", dss.handleStorageClientStats)
|
mux.HandleFunc("/api/storagedeal/totalreal", dss.handleStorageDealTotalReal)
|
||||||
|
mux.HandleFunc("/api/storagedeal/clientstats", dss.handleStorageClientStats)
|
||||||
|
|
||||||
panic(http.ListenAndServe(":7272", nil))
|
s := &http.Server{
|
||||||
|
Addr: ":7272",
|
||||||
|
Handler: mux,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
s.Shutdown(context.TODO())
|
||||||
|
}()
|
||||||
|
|
||||||
|
list, err := net.Listen("tcp", ":7272")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Serve(list)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user