Skip to content

Commit

Permalink
Add context to raw pusher interface and calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Jul 13, 2023
1 parent b373475 commit aa46a70
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion push/buford/buford.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package buford

import (
"context"
"crypto/tls"
"errors"
"net/http"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (c *bufordPushProvider) pushMulti(pushInfos []*mdm.Push) map[string]*push.R
}

// Push sends 'raw' MDM APNs push notifications to service in c.
func (c *bufordPushProvider) Push(pushInfos []*mdm.Push) (map[string]*push.Response, error) {
func (c *bufordPushProvider) Push(_ context.Context, pushInfos []*mdm.Push) (map[string]*push.Response, error) {
if len(pushInfos) < 1 {
return nil, errors.New("no push data provided")
}
Expand Down
3 changes: 1 addition & 2 deletions push/nanopush/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ func (p *Provider) pushConcurrent(ctx context.Context, pushInfos []*mdm.Push) (m
}

// Push sends APNs pushes to MDM enrollments.
func (p *Provider) Push(pushInfos []*mdm.Push) (map[string]*push.Response, error) {
ctx := context.TODO()
func (p *Provider) Push(ctx context.Context, pushInfos []*mdm.Push) (map[string]*push.Response, error) {
if len(pushInfos) < 1 {
return nil, errors.New("no push data provided")
} else if len(pushInfos) == 1 {
Expand Down
3 changes: 2 additions & 1 deletion push/nanopush/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nanopush

import (
"bytes"
"context"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestPush(t *testing.T) {
}
pushInfo.SetTokenString(deviceToken)

resp, err := prov.Push([]*mdm.Push{pushInfo})
resp, err := prov.Push(context.Background(), []*mdm.Push{pushInfo})
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Pusher interface {
// The non-error return type maps the string value of the push token
// (that is, the hex encoding of the bytes) to a pointer to a Response.
type PushProvider interface {
Push([]*mdm.Push) (map[string]*Response, error)
Push(context.Context, []*mdm.Push) (map[string]*Response, error)
}

// PushProviderFactory generates a new PushProvider given a tls keypair
Expand Down
4 changes: 2 additions & 2 deletions push/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *PushService) pushSingle(ctx context.Context, pushInfo *mdm.Push) (map[s
if err != nil {
return nil, err
}
return prov.Push([]*mdm.Push{pushInfo})
return prov.Push(ctx, []*mdm.Push{pushInfo})
}

// pushMulti sends pushes to (potentially) multiple push providers
Expand All @@ -128,7 +128,7 @@ func (s *PushService) pushMulti(ctx context.Context, pushInfos []*mdm.Push) (map
}
topicPushCt += 1
go func(prov push.PushProvider, pushInfos []*mdm.Push, feedback chan<- pushFeedback, topic string) {
resp, err := prov.Push(pushInfos)
resp, err := prov.Push(ctx, pushInfos)
feedback <- pushFeedback{
Responses: resp,
Err: err,
Expand Down

0 comments on commit aa46a70

Please sign in to comment.