From 04ab6167c734202bd6a8b51447cf869440ef86ae Mon Sep 17 00:00:00 2001 From: Max Ignatenko Date: Thu, 14 Nov 2024 12:36:39 +0000 Subject: [PATCH] fix: use LastRecordTimestamp in serve() instead of LastSuccess --- cmd/plc-mirror/serve.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/plc-mirror/serve.go b/cmd/plc-mirror/serve.go index bc49847..520de27 100644 --- a/cmd/plc-mirror/serve.go +++ b/cmd/plc-mirror/serve.go @@ -66,7 +66,11 @@ func (s *Server) serve(ctx context.Context, req *http.Request) convreq.HttpRespo requestLatency.WithLabelValues(fmt.Sprint(c)).Observe(float64(time.Now().Sub(start)) / float64(time.Millisecond)) } - delay := time.Since(s.mirror.LastSuccess()) + ts, err := s.mirror.LastRecordTimestamp(ctx) + if err != nil { + return respond.InternalServerError(err.Error()) + } + delay := time.Since(ts) if delay > s.MaxDelay { updateMetrics(http.StatusServiceUnavailable) return respond.ServiceUnavailable(fmt.Sprintf("mirror is %s behind", delay)) @@ -75,7 +79,7 @@ func (s *Server) serve(ctx context.Context, req *http.Request) convreq.HttpRespo requestedDid := strings.ToLower(strings.TrimPrefix(req.URL.Path, "/")) var entry PLCLogEntry - err := s.db.Model(&entry).Where("did = ? AND (NOT nullified)", requestedDid).Order("plc_timestamp desc").Limit(1).Take(&entry).Error + err = s.db.Model(&entry).Where("did = ? AND (NOT nullified)", requestedDid).Order("plc_timestamp desc").Limit(1).Take(&entry).Error if errors.Is(err, gorm.ErrRecordNotFound) { updateMetrics(http.StatusNotFound) return respond.NotFound("unknown DID")