mirror of
https://github.com/LBRYFoundation/herald.go.git
synced 2025-08-23 17:47:27 +00:00
Don't swallow error, cachettl and refresh delta as params
This commit is contained in:
parent
220a42984e
commit
a6d47e662a
3 changed files with 33 additions and 23 deletions
30
main.go
30
main.go
|
@ -18,11 +18,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultHost = "0.0.0.0"
|
defaultHost = "0.0.0.0"
|
||||||
defaultPort = "50051"
|
defaultPort = "50051"
|
||||||
defaultEsHost = "http://localhost"
|
defaultEsHost = "http://localhost"
|
||||||
defaultEsIndex = "claims"
|
defaultEsIndex = "claims"
|
||||||
defaultEsPort = "9200"
|
defaultEsPort = "9200"
|
||||||
|
defaultRefreshDelta = 5
|
||||||
|
defaultCacheTTL = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string {
|
func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string {
|
||||||
|
@ -71,6 +73,8 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
||||||
esHost := parser.String("", "eshost", &argparse.Options{Required: false, Help: "elasticsearch host", Default: defaultEsHost})
|
esHost := parser.String("", "eshost", &argparse.Options{Required: false, Help: "elasticsearch host", Default: defaultEsHost})
|
||||||
esPort := parser.String("", "esport", &argparse.Options{Required: false, Help: "elasticsearch port", Default: defaultEsPort})
|
esPort := parser.String("", "esport", &argparse.Options{Required: false, Help: "elasticsearch port", Default: defaultEsPort})
|
||||||
esIndex := parser.String("", "esindex", &argparse.Options{Required: false, Help: "elasticsearch index name", Default: defaultEsIndex})
|
esIndex := parser.String("", "esindex", &argparse.Options{Required: false, Help: "elasticsearch index name", Default: defaultEsIndex})
|
||||||
|
refreshDelta := parser.Int("", "refresh-delta", &argparse.Options{Required: false, Help: "elasticsearch index refresh delta in seconds", Default: defaultRefreshDelta})
|
||||||
|
cacheTTL := parser.Int("", "cachettl", &argparse.Options{Required: false, Help: "Cache TTL in minutes", Default: defaultCacheTTL})
|
||||||
|
|
||||||
text := parser.String("", "text", &argparse.Options{Required: false, Help: "text query"})
|
text := parser.String("", "text", &argparse.Options{Required: false, Help: "text query"})
|
||||||
name := parser.String("", "name", &argparse.Options{Required: false, Help: "name"})
|
name := parser.String("", "name", &argparse.Options{Required: false, Help: "name"})
|
||||||
|
@ -89,13 +93,15 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
args := &server.Args{
|
args := &server.Args{
|
||||||
CmdType: server.SearchCmd,
|
CmdType: server.SearchCmd,
|
||||||
Host: *host,
|
Host: *host,
|
||||||
Port: ":" + *port,
|
Port: ":" + *port,
|
||||||
EsHost: *esHost,
|
EsHost: *esHost,
|
||||||
EsPort: *esPort,
|
EsPort: *esPort,
|
||||||
EsIndex: *esIndex,
|
EsIndex: *esIndex,
|
||||||
Debug: *debug,
|
Debug: *debug,
|
||||||
|
RefreshDelta: *refreshDelta,
|
||||||
|
CacheTTL: *cacheTTL,
|
||||||
}
|
}
|
||||||
|
|
||||||
if esHost, ok := environment["ELASTIC_HOST"]; ok {
|
if esHost, ok := environment["ELASTIC_HOST"]; ok {
|
||||||
|
|
|
@ -199,8 +199,10 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs,
|
||||||
// 0 seconds in debug / unit testing). If the index has been refreshed
|
// 0 seconds in debug / unit testing). If the index has been refreshed
|
||||||
// a different number of times since we last checked, we purge the cache
|
// a different number of times since we last checked, we purge the cache
|
||||||
if time.Now().After(s.LastRefreshCheck.Add(s.RefreshDelta)) {
|
if time.Now().After(s.LastRefreshCheck.Add(s.RefreshDelta)) {
|
||||||
// FIXME: Should this be on all indices
|
res, err := client.IndexStats(searchIndices[0]).Do(ctx)
|
||||||
res, _ := client.IndexStats(searchIndices[0]).Do(ctx)
|
if err != nil {
|
||||||
|
log.Printf("Error on ES index stats\n%v\n", err)
|
||||||
|
}
|
||||||
numRefreshes := res.Indices[searchIndices[0]].Primaries.Refresh.Total
|
numRefreshes := res.Indices[searchIndices[0]].Primaries.Refresh.Total
|
||||||
if numRefreshes != s.NumESRefreshes {
|
if numRefreshes != s.NumESRefreshes {
|
||||||
_ = s.QueryCache.Purge()
|
_ = s.QueryCache.Purge()
|
||||||
|
|
|
@ -48,13 +48,15 @@ const (
|
||||||
|
|
||||||
type Args struct {
|
type Args struct {
|
||||||
// TODO Make command types an enum
|
// TODO Make command types an enum
|
||||||
CmdType int
|
CmdType int
|
||||||
Host string
|
Host string
|
||||||
Port string
|
Port string
|
||||||
EsHost string
|
EsHost string
|
||||||
EsPort string
|
EsPort string
|
||||||
EsIndex string
|
EsIndex string
|
||||||
Debug bool
|
Debug bool
|
||||||
|
RefreshDelta int
|
||||||
|
CacheTTL int
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVersion() string {
|
func getVersion() string {
|
||||||
|
@ -132,12 +134,12 @@ func MakeHubServer(args *Args) *Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := ttlcache.NewCache()
|
cache := ttlcache.NewCache()
|
||||||
err = cache.SetTTL(5 * time.Minute)
|
err = cache.SetTTL(time.Duration(args.CacheTTL) * time.Minute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
s256 := sha256.New()
|
s256 := sha256.New()
|
||||||
var refreshDelta = time.Second * 2
|
var refreshDelta = time.Second * time.Duration(args.RefreshDelta)
|
||||||
if args.Debug {
|
if args.Debug {
|
||||||
refreshDelta = time.Second * 0
|
refreshDelta = time.Second * 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue