Skip to content

Commit

Permalink
listen bucket: Support empty events from the server
Browse files Browse the repository at this point in the history
Ask the server to send empty events to clear the buffer scanner which
can be filled with whitespaces but without new lines when the bucket is
idle and without any events
  • Loading branch information
Anis Elleuch committed Apr 15, 2023
1 parent e09cb21 commit 9df4e4e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api-bucket-notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (c *Client) ListenBucketNotification(ctx context.Context, bucketName, prefi

// Prepare urlValues to pass into the request on every loop
urlValues := make(url.Values)
urlValues.Set("ping", "true")
urlValues.Set("prefix", prefix)
urlValues.Set("suffix", suffix)
urlValues["events"] = events
Expand Down Expand Up @@ -224,6 +225,12 @@ func (c *Client) ListenBucketNotification(ctx context.Context, bucketName, prefi
closeResponse(resp)
continue
}

// Empty events pinged from the server
if len(notificationInfo.Records) == 0 && notificationInfo.Err == nil {
continue
}

// Send notificationInfo
select {
case notificationInfoCh <- notificationInfo:
Expand Down

0 comments on commit 9df4e4e

Please sign in to comment.