Documentation
¶
Index ¶
Constants ¶
const HooksStreamName = "HOOKS"
Variables ¶
var DefaultRetryPolicy = RetryPolicy{ For: 2 * time.Minute, InitialInterval: time.Second, MaxInterval: 15 * time.Second, }
DefaultRetryPolicy outlasts a NATS server restart, which takes about a minute during a rollout or a node replacement.
Functions ¶
func PublishWithRetry ¶ added in v0.8.6
func PublishWithRetry(publish func() error, policy RetryPolicy, done func(err error, attempts int)) bool
PublishWithRetry calls publish once. If that fails, it returns false right away and keeps calling publish in the background, backing off, until it succeeds or the policy's time runs out.
Webhook handlers use this because neither GitLab nor GitHub resends a webhook delivery on its own, and GitLab disables a webhook after four failed deliveries in a row. So the handler must answer quickly and with a 2xx even when NATS is briefly unavailable, and the event has to be kept alive here instead.
done is called exactly once, with the final error (nil when the event was published) and the number of attempts, from the background goroutine when the first attempt failed.
Types ¶
type HooksStream ¶
type HooksStream struct {
// contains filtered or unexported fields
}
func NewHooksStream ¶
func NewHooksStream(nc *nats.Conn) *HooksStream
func (*HooksStream) HealthCheck ¶
func (s *HooksStream) HealthCheck() error
type RetryPolicy ¶ added in v0.8.6
type RetryPolicy struct {
// For is how long to keep retrying after the first attempt failed.
For time.Duration
// InitialInterval and MaxInterval bound the backoff between attempts.
InitialInterval time.Duration
MaxInterval time.Duration
}
RetryPolicy bounds how a webhook event that could not be published is retried in the background.