Skip to content

Commit

Permalink
retrying
Browse files Browse the repository at this point in the history
  • Loading branch information
kazeburo committed Sep 24, 2021
1 parent cd50b71 commit 93c361c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gcal.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (g *GcalClient) getEvents(start, end time.Time, calId string) (*calendar.Ev
SingleEvents(true).
TimeMin(startStr).
TimeMax(endStr).
MaxResults(9999).
MaxResults(2500).
OrderBy("startTime").Do()
if err != nil {
return nil, err
Expand Down
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"math/rand"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -191,8 +192,25 @@ func main() {
diff := cmp.Diff(exceptEvent, foundGcalEvent, cmpopts.IgnoreFields(*exceptEvent, "Created", "Creator", "Etag", "ICalUID", "Id", "HtmlLink", "Status", "Updated", "Reminders", "Organizer", "Kind", "Sequence"))
if diff != "" {
fmt.Printf("Update event %s\n%s\n\n", srcEvent.Subject, diff)
_, err := gcal.service.Events.Update(calId, foundGcalEvent.Id, exceptEvent).Do()
if err != nil {
maxRetries := 5
retries := 0
var lasterr error
for {
_, lasterr := gcal.service.Events.Update(calId, foundGcalEvent.Id, exceptEvent).Do()
if lasterr != nil {
if retries > maxRetries {
break
}

waitTime := (2 << retries) + rand.Intn(1000)/1000
time.Sleep(time.Duration(waitTime) * time.Second)

retries++
continue
}
break
}
if lasterr != nil {
panic(err)
}
} else {
Expand Down

0 comments on commit 93c361c

Please sign in to comment.