Skip to content

Commit

Permalink
Adjust refresh station start based on incoming data.
Browse files Browse the repository at this point in the history
Since people can upload more than two days of data at once this looks
to the times in the data itself to determine how far back we should
refresh. It keeps the 2 day minimum.
  • Loading branch information
jlewallen committed Nov 25, 2020
1 parent 5f430b8 commit 8db16e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/backend/ingestion_received_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ func (h *IngestionReceivedHandler) Handle(ctx context.Context, m *messages.Inges
}

if info.StationID != nil {
now := time.Now()
howFarBack := time.Hour * 48
if now.After(info.DataStart) {
howFarBack += now.Sub(info.DataStart)
log.Infow("refreshing", "how_far_back", howFarBack)
} else {
log.Warnw("data-after-now", "data_start", info.DataStart, "data_end", info.DataEnd, "now", now)
}
if err := h.publisher.Publish(ctx, &messages.RefreshStation{
StationID: *info.StationID,
HowRecently: time.Hour * 48,
HowRecently: howFarBack,
Completely: false,
UserID: i.UserID,
}); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions server/backend/record_adder.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ type WriteInfo struct {
MetaErrors int64
DataErrors int64
StationID *int32
DataStart time.Time
DataEnd time.Time
}

func (ra *RecordAdder) fixDataRecord(ctx context.Context, record *pb.DataRecord) (bool, error) {
Expand Down Expand Up @@ -307,6 +309,8 @@ func (ra *RecordAdder) WriteRecords(ctx context.Context, i *data.Ingestion) (inf
MetaErrors: int64(metaErrors),
DataErrors: int64(dataErrors),
StationID: stationID,
DataStart: ra.statistics.start,
DataEnd: ra.statistics.end,
}

return
Expand Down

0 comments on commit 8db16e0

Please sign in to comment.