mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-06-20 09:56:49 +02:00
internal/server/server.go: Make OnTick() interval configurable.
This commit is contained in:
parent
a73f1eae8b
commit
62d039deb2
2 changed files with 9 additions and 4 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/eosswedenorg-go/pid"
|
||||
"github.com/eosswedenorg/antelope-api-healthcheck/internal/server"
|
||||
|
|
@ -182,7 +183,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Create server
|
||||
srv = server.New(argv_listen_addr())
|
||||
srv = server.New(argv_listen_addr(), time.Second*10)
|
||||
|
||||
// Run signal event loop in its own goroutine
|
||||
go signalEventLoop()
|
||||
|
|
|
|||
|
|
@ -23,11 +23,15 @@ type Server struct {
|
|||
|
||||
// Number of connections between each OnTick()
|
||||
num_conn uint64
|
||||
|
||||
// Time between each call to OnTick()
|
||||
tick_interval time.Duration
|
||||
}
|
||||
|
||||
func New(addr string) *Server {
|
||||
func New(addr string, tick_interval time.Duration) *Server {
|
||||
return &Server{
|
||||
addr: fmt.Sprintf("tcp://%s", addr),
|
||||
addr: fmt.Sprintf("tcp://%s", addr),
|
||||
tick_interval: tick_interval,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +65,7 @@ func (s *Server) OnTick() (time.Duration, gnet.Action) {
|
|||
"current_connections": s.eng.CountConnections(),
|
||||
})
|
||||
atomic.StoreUint64(&s.num_conn, 0)
|
||||
return time.Second * 10, gnet.None
|
||||
return s.tick_interval, gnet.None
|
||||
}
|
||||
|
||||
// OnTraffic callback function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue