Skip to content

Commit

Permalink
update 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
nukokusa committed Oct 16, 2023
1 parent 573c3c9 commit 1dc5f27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions calendar.go
Expand Up @@ -65,24 +65,21 @@ type CalendarService interface {
}

type calendarService struct {
cs *calendar.Service
policy retry.Policy
cs *calendar.Service
}

var policy = retry.Policy{
MinDelay: time.Second,
MaxDelay: 100 * time.Second,
MaxCount: 10,
}

func newCalendarService(ctx context.Context, credentialPath string) (CalendarService, error) {
cs, err := calendar.NewService(ctx, option.WithCredentialsFile(credentialPath))
if err != nil {
return nil, errors.Wrap(err, "error calendar.NewService")
}
policy := retry.Policy{
MinDelay: time.Second,
MaxDelay: 100 * time.Second,
MaxCount: 10,
}
return &calendarService{
cs: cs,
policy: policy,
}, nil
return &calendarService{cs: cs}, nil
}

func (s *calendarService) List(ctx context.Context, calendarID string, startTime, endTime time.Time) ([]*Event, error) {
Expand All @@ -95,7 +92,7 @@ func (s *calendarService) List(ctx context.Context, calendarID string, startTime

pageToken := ""
for {
retrier := s.policy.Start(ctx)
retrier := policy.Start(ctx)
var resp *calendar.Events
for retrier.Continue() {
var err error
Expand Down Expand Up @@ -143,7 +140,7 @@ func (s *calendarService) Insert(ctx context.Context, calendarID string, event *
}
req := s.cs.Events.Insert(calendarID, ev)

retrier := s.policy.Start(ctx)
retrier := policy.Start(ctx)
var resp *calendar.Event
for retrier.Continue() {
var err error
Expand Down Expand Up @@ -187,7 +184,7 @@ func (s *calendarService) Update(ctx context.Context, calendarID string, event *
}
req := s.cs.Events.Update(calendarID, ev.Id, ev)

retrier := s.policy.Start(ctx)
retrier := policy.Start(ctx)
var resp *calendar.Event
for retrier.Continue() {
var err error
Expand All @@ -213,7 +210,7 @@ func (s *calendarService) Update(ctx context.Context, calendarID string, event *

func (s *calendarService) get(ctx context.Context, calendarID string, eventID string) (*calendar.Event, error) {
req := s.cs.Events.Get(calendarID, eventID)
retrier := s.policy.Start(ctx)
retrier := policy.Start(ctx)
var ev *calendar.Event
for retrier.Continue() {
var err error
Expand All @@ -235,7 +232,7 @@ func (s *calendarService) get(ctx context.Context, calendarID string, eventID st

func (s *calendarService) Delete(ctx context.Context, calendarID, eventID string) error {
req := s.cs.Events.Delete(calendarID, eventID)
retrier := s.policy.Start(ctx)
retrier := policy.Start(ctx)
for retrier.Continue() {
err := req.Context(ctx).Do()
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,6 +1,6 @@
module github.com/nukokusa/koyomi

go 1.20
go 1.21

require (
github.com/Songmu/flextime v0.1.0
Expand Down

0 comments on commit 1dc5f27

Please sign in to comment.