mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
This commit moves ID-related types and functions to the top level package and moves remaining statsd wrapper into a `statsd` package.
62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package core
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"time"
|
|
|
|
"github.com/umbel/pilosa"
|
|
"github.com/umbel/pilosa/db"
|
|
)
|
|
|
|
type PingRequest struct {
|
|
Id *pilosa.GUID
|
|
Source *pilosa.GUID
|
|
}
|
|
|
|
type PongRequest struct {
|
|
Id *pilosa.GUID
|
|
}
|
|
|
|
func (self PongRequest) ResultId() *pilosa.GUID {
|
|
return self.Id
|
|
}
|
|
func (self PongRequest) ResultData() interface{} {
|
|
return self.Id
|
|
}
|
|
|
|
func init() {
|
|
gob.Register(PingRequest{})
|
|
gob.Register(PongRequest{})
|
|
}
|
|
|
|
type Pinger struct {
|
|
ID pilosa.GUID
|
|
|
|
Hold interface {
|
|
Get(id *pilosa.GUID, timeout time.Duration) (interface{}, error)
|
|
}
|
|
|
|
Transport interface {
|
|
Send(message *db.Message, host *pilosa.GUID)
|
|
}
|
|
}
|
|
|
|
func NewPinger(id pilosa.GUID) *Pinger {
|
|
return &Pinger{
|
|
ID: id,
|
|
}
|
|
}
|
|
|
|
func (self *Pinger) Ping(process_id *pilosa.GUID) (*time.Duration, error) {
|
|
id := pilosa.RandomUUID()
|
|
ping := db.Message{Data: PingRequest{Id: &id, Source: &self.ID}}
|
|
start := time.Now()
|
|
self.Transport.Send(&ping, process_id)
|
|
_, err := self.Hold.Get(&id, 60*time.Second)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
end := time.Now()
|
|
dur := end.Sub(start)
|
|
return &dur, nil
|
|
}
|