Skip to content

Commit

Permalink
fixed pagination loop
Browse files Browse the repository at this point in the history
  • Loading branch information
frese committed Aug 5, 2020
1 parent 87b8b2d commit 3132e41
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ INCIDENTS:
func pdGetIncidentsSince(since time.Time) []pagerduty.Incident {

incidents := make([]pagerduty.Incident, 0)
resp := &pagerduty.ListIncidentsResponse{}

opts := pagerduty.ListIncidentsOptions{
Since: since.Format(time.RFC3339),
Expand All @@ -183,15 +182,16 @@ func pdGetIncidentsSince(since time.Time) []pagerduty.Incident {
},
}

for ok := true; ok; ok = resp.APIListObject.More {
ok := true
for ok {
log.Printf("API query since: %s, Limit: %v Offset: %v", since, opts.APIListObject.Limit, opts.APIListObject.Offset)
resp, err := pd.ListIncidents(opts)
if err != nil {
log.Println("Error: Cannot list incidents from Pagerduty API:", err)
return incidents
}
ok = resp.APIListObject.More
log.Printf("Got %d incidents", len(resp.Incidents))
log.Printf("APIListObject %+v", resp.APIListObject)
incidents = append(incidents, resp.Incidents...)
opts.APIListObject.Offset = opts.APIListObject.Offset + opts.APIListObject.Limit
}
Expand Down

0 comments on commit 3132e41

Please sign in to comment.