Skip to content

Commit

Permalink
fix: dont override checkpoint if list deliveries is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
shankiyani committed Jan 13, 2025
1 parent f260eba commit a793476
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (s *Server) handleRetry() http.Handler {
// ensure we run the loop at least once
for ok := true; ok; ok = (cursor != "" && !found) {
// call list deliveries API, first call is intentionally an empty string
// data is returned sorted by created_at in descending order (latest event first)
deliveries, res, err := s.github.ListDeliveries(ctx, &github.ListCursorOptions{
Cursor: cursor,
PerPage: 100,
Expand Down Expand Up @@ -144,7 +145,7 @@ func (s *Server) handleRetry() http.Handler {
// update the cursor
cursor = res.Cursor

// for each failed delivery, redeliver
// for each delivery, load the failed deliveries into a list for later processing
for i := 0; i < len(deliveries); i++ {
// append to the total events counter
totalEventCount += 1
Expand Down Expand Up @@ -225,11 +226,20 @@ func (s *Server) handleRetry() http.Handler {
}

// advance the checkpoint to the first entry read on this run to avoid
// redundant processing
newCheckpoint = firstCheckpoint
// redundant processing, handle edge case where the list deliveries API
// does not return any events
if firstCheckpoint == "" {
logger.WarnContext(ctx, "ListDeliveries request did not return any deliveries, skipping checkpoint update")
} else {
newCheckpoint = firstCheckpoint

logger.DebugContext(ctx, "updating checkpoint",
"new_checkpoint", newCheckpoint,
)

s.writeMostRecentCheckpoint(ctx, w, newCheckpoint, prevCheckpoint, now,
totalEventCount, failedEventCount, redeliveredEventCount)
s.writeMostRecentCheckpoint(ctx, w, newCheckpoint, prevCheckpoint, now,
totalEventCount, failedEventCount, redeliveredEventCount)
}

logger.InfoContext(ctx, "successful",
"code", http.StatusAccepted,
Expand Down

0 comments on commit a793476

Please sign in to comment.