-
Notifications
You must be signed in to change notification settings - Fork 0
/
backoff.go
48 lines (40 loc) · 972 Bytes
/
backoff.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package mongoout
import (
"context"
b "github.com/elastic/beats/v7/libbeat/common/backoff"
"github.com/elastic/beats/v7/libbeat/outputs"
"github.com/elastic/beats/v7/libbeat/publisher"
"time"
)
type backoffClient struct {
client *client
done chan struct{}
backoff b.Backoff
}
var _ outputs.NetworkClient = &backoffClient{}
func newBackoffClient(client *client, init, max time.Duration) *backoffClient {
done := make(chan struct{})
backoff := b.NewEqualJitterBackoff(done, init, max)
return &backoffClient{
client: client,
done: done,
backoff: backoff,
}
}
func (b *backoffClient) Close() error {
close(b.done)
return b.client.Close()
}
func (b *backoffClient) Publish(ctx context.Context, batch publisher.Batch) error {
err := b.client.Publish(ctx, batch)
if err != nil {
b.backoff.Wait()
}
return err
}
func (b *backoffClient) String() string {
return b.client.String()
}
func (b *backoffClient) Connect() error {
return nil
}