Mercurial > gemma
changeset 4281:c470d2202823
Limit time range requested from fa services.
This is a workaround, so that services which limit the amount of
results in there responses don't bail out, when the latest data is
very old.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Thu, 29 Aug 2019 16:59:47 +0200 |
parents | 2f2dbd3ebaea |
children | 5d6a4dd3efa1 |
files | pkg/imports/fa.go |
diffstat | 1 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/fa.go Thu Aug 29 16:31:37 2019 +0200 +++ b/pkg/imports/fa.go Thu Aug 29 16:59:47 2019 +0200 @@ -38,8 +38,12 @@ Insecure bool `json:"insecure"` } -// FAJobKind is import queue type identifier. -const FAJobKind JobKind = "fa" +const ( + // FAJobKind is import queue type identifier. + FAJobKind JobKind = "fa" + // Upper limit for days to request + MaxHistoryDays int = 7 +) const ( listBottlenecksSQL = ` @@ -214,12 +218,22 @@ switch { case err == sql.ErrNoRows: date = pgtype.Timestamp{ - // Fill Database with data of the last 5 days. Change this to a more useful value. - Time: time.Now().AddDate(0, 0, -5), + Time: time.Now().AddDate(0, 0, MaxHistoryDays*-1), } case err != nil: return pgtype.Timestamp{}, err } + // Limit request range to MaxHistoryDays. Otherwise the Request might + // fail, e.g. the AT service has an upper liimit of 10000 results. + // + // FIXME: the better solution would be to detect such errors and + // dynamically and implement some kind of chunking... + if time.Since(date.Time).Hours() > float64(MaxHistoryDays*24) { + date = pgtype.Timestamp{ + Time: time.Now().AddDate(0, 0, MaxHistoryDays*-1), + } + } + return date, nil }