mirror of
https://github.com/creekorful/bathyscaphe
synced 2024-11-19 15:25:44 +00:00
API: fix startDate/endDate query param
This commit is contained in:
parent
62b54bf385
commit
b85e9944a2
@ -125,7 +125,7 @@ func searchResources(es *elastic.Client) echo.HandlerFunc {
|
||||
startDate := time.Time{}
|
||||
if val := c.QueryParam("start-date"); val != "" {
|
||||
d, err := time.Parse(time.RFC3339, val)
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
startDate = d
|
||||
}
|
||||
}
|
||||
@ -133,7 +133,7 @@ func searchResources(es *elastic.Client) echo.HandlerFunc {
|
||||
endDate := time.Time{}
|
||||
if val := c.QueryParam("end-date"); val != "" {
|
||||
d, err := time.Parse(time.RFC3339, val)
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
endDate = d
|
||||
}
|
||||
}
|
||||
@ -231,19 +231,23 @@ func addResource(es *elastic.Client) echo.HandlerFunc {
|
||||
func buildSearchQuery(url, keyword string, startDate, endDate time.Time) elastic.Query {
|
||||
var queries []elastic.Query
|
||||
if url != "" {
|
||||
log.Trace().Str("url", url).Msg("SearchQuery: Setting url")
|
||||
queries = append(queries, elastic.NewTermQuery("url", url))
|
||||
}
|
||||
if keyword != "" {
|
||||
log.Trace().Str("body", keyword).Msg("SearchQuery: Setting body")
|
||||
queries = append(queries, elastic.NewTermQuery("body", keyword))
|
||||
}
|
||||
if !startDate.IsZero() || !endDate.IsZero() {
|
||||
timeQuery := elastic.NewRangeQuery("time")
|
||||
|
||||
if !startDate.IsZero() {
|
||||
timeQuery.Gte(startDate)
|
||||
log.Trace().Str("startDate", startDate.Format(time.RFC3339)).Msg("SearchQuery: Setting startDate")
|
||||
timeQuery.Gte(startDate.Format(time.RFC3339))
|
||||
}
|
||||
if !endDate.IsZero() {
|
||||
timeQuery.Lte(endDate)
|
||||
log.Trace().Str("endDate", endDate.Format(time.RFC3339)).Msg("SearchQuery: Setting endDate")
|
||||
timeQuery.Lte(endDate.Format(time.RFC3339))
|
||||
}
|
||||
queries = append(queries, timeQuery)
|
||||
}
|
||||
|
@ -51,6 +51,13 @@ func execute(ctx *cli.Context) error {
|
||||
log.Debug().Str("uri", ctx.String("nats-uri")).Msg("Using NATS server")
|
||||
log.Debug().Str("uri", ctx.String("api-uri")).Msg("Using API server")
|
||||
|
||||
refreshDelay := parseRefreshDelay(ctx.String("refresh-delay"))
|
||||
if refreshDelay != -1 {
|
||||
log.Debug().Stringer("delay", refreshDelay).Msg("Existing resources will be crawled again")
|
||||
} else {
|
||||
log.Debug().Msg("Existing resources will NOT be crawled again")
|
||||
}
|
||||
|
||||
// Create the API client
|
||||
apiClient := api.NewClient(ctx.String("api-uri"))
|
||||
|
||||
@ -63,8 +70,7 @@ func execute(ctx *cli.Context) error {
|
||||
|
||||
log.Info().Msg("Successfully initialized tdsh-scheduler. Waiting for URLs")
|
||||
|
||||
if err := sub.QueueSubscribe(messaging.URLFoundSubject, "schedulers",
|
||||
handleMessage(apiClient, parseRefreshDelay(ctx.String("refresh-delay")))); err != nil {
|
||||
if err := sub.QueueSubscribe(messaging.URLFoundSubject, "schedulers", handleMessage(apiClient, refreshDelay)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -96,10 +102,7 @@ func handleMessage(apiClient api.Client, refreshDelay time.Duration) natsutil.Ms
|
||||
// that are newer than now-refreshDelay.
|
||||
endDate := time.Time{}
|
||||
if refreshDelay != -1 {
|
||||
log.Debug().Stringer("delay", refreshDelay).Msg("Existing resources will be crawled again")
|
||||
endDate = time.Now().Add(-refreshDelay)
|
||||
} else {
|
||||
log.Debug().Msg("Existing resources will NOT be crawled again")
|
||||
}
|
||||
|
||||
b64URI := base64.URLEncoding.EncodeToString([]byte(u.String()))
|
||||
|
@ -26,4 +26,6 @@ func ConfigureLogger(ctx *cli.Context) {
|
||||
} else {
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
}
|
||||
|
||||
log.Debug().Stringer("lvl", zerolog.GlobalLevel()).Msg("Setting log level")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user