Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dont override checkpoint if list deliveries is empty #355

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
shankiyani marked this conversation as resolved.
Show resolved Hide resolved

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
Loading