Skip to content

Commit

Permalink
Merge pull request #75 from foodora/awssub-on-error-func
Browse files Browse the repository at this point in the history
introduce error handling function
  • Loading branch information
Muharem Ismailov committed Sep 18, 2019
2 parents 24ddbf9 + ada3ca6 commit fc00051
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pubsub/awssub/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type (
sqsErr error

Logger pubsub.Logger

// onErrorFunc is a func is being called when an error occurs
onErrorFunc func(error)
}

// SQSMessage is the SQS implementation of `SubscriberMessage`.
Expand Down Expand Up @@ -261,6 +264,9 @@ func (s *subscriber) Start() <-chan pubsub.Message {
// we've encountered a major error
s.Logger.Printf("Error occurred %s", err.Error())
s.sqsErr = err
if s.onErrorFunc != nil {
s.onErrorFunc(err)
}
time.Sleep(s.cfg.SleepInterval)
continue
}
Expand Down Expand Up @@ -291,6 +297,11 @@ func (s *subscriber) Start() <-chan pubsub.Message {
return output
}

// OnErrorFunc sets subscriber's onErrorFunc field
func (s *subscriber) SetOnErrorFunc(fn func(error)) {
s.onErrorFunc = fn
}

func (s *subscriber) handleDeletes() {
var entriesBuffer []*sqs.DeleteMessageBatchRequestEntry
for {
Expand Down

0 comments on commit fc00051

Please sign in to comment.