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 (
|
||||
defaultHost = "0.0.0.0"
|
||||
defaultPort = "50051"
|
||||
defaultEsHost = "http://localhost"
|
||||
defaultEsIndex = "claims"
|
||||
defaultEsPort = "9200"
|
||||
defaultHost = "0.0.0.0"
|
||||
defaultPort = "50051"
|
||||
defaultEsHost = "http://localhost"
|
||||
defaultEsIndex = "claims"
|
||||
defaultEsPort = "9200"
|
||||
defaultRefreshDelta = 5
|
||||
defaultCacheTTL = 5
|
||||
)
|
||||
|
||||
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})
|
||||
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})
|
||||
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"})
|
||||
name := parser.String("", "name", &argparse.Options{Required: false, Help: "name"})
|
||||
|
@ -89,13 +93,15 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
|||
}
|
||||
|
||||
args := &server.Args{
|
||||
CmdType: server.SearchCmd,
|
||||
Host: *host,
|
||||
Port: ":" + *port,
|
||||
EsHost: *esHost,
|
||||
EsPort: *esPort,
|
||||
EsIndex: *esIndex,
|
||||
Debug: *debug,
|
||||
CmdType: server.SearchCmd,
|
||||
Host: *host,
|
||||
Port: ":" + *port,
|
||||
EsHost: *esHost,
|
||||
EsPort: *esPort,
|
||||
EsIndex: *esIndex,
|
||||
Debug: *debug,
|
||||
RefreshDelta: *refreshDelta,
|
||||
CacheTTL: *cacheTTL,
|
||||
}
|
||||
|
||||
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
|
||||
// a different number of times since we last checked, we purge the cache
|
||||
if time.Now().After(s.LastRefreshCheck.Add(s.RefreshDelta)) {
|
||||
// FIXME: Should this be on all indices
|
||||
res, _ := client.IndexStats(searchIndices[0]).Do(ctx)
|
||||
res, err := 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
|
||||
if numRefreshes != s.NumESRefreshes {
|
||||
_ = s.QueryCache.Purge()
|
||||
|
|
|
@ -48,13 +48,15 @@ const (
|
|||
|
||||
type Args struct {
|
||||
// TODO Make command types an enum
|
||||
CmdType int
|
||||
Host string
|
||||
Port string
|
||||
EsHost string
|
||||
EsPort string
|
||||
EsIndex string
|
||||
Debug bool
|
||||
CmdType int
|
||||
Host string
|
||||
Port string
|
||||
EsHost string
|
||||
EsPort string
|
||||
EsIndex string
|
||||
Debug bool
|
||||
RefreshDelta int
|
||||
CacheTTL int
|
||||
}
|
||||
|
||||
func getVersion() string {
|
||||
|
@ -132,12 +134,12 @@ func MakeHubServer(args *Args) *Server {
|
|||
}
|
||||
|
||||
cache := ttlcache.NewCache()
|
||||
err = cache.SetTTL(5 * time.Minute)
|
||||
err = cache.SetTTL(time.Duration(args.CacheTTL) * time.Minute)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
s256 := sha256.New()
|
||||
var refreshDelta = time.Second * 2
|
||||
var refreshDelta = time.Second * time.Duration(args.RefreshDelta)
|
||||
if args.Debug {
|
||||
refreshDelta = time.Second * 0
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue