Passed
Push — master ( 00fce0...e4f177 )
by eval
02:21 queued 32s
created

sqs/client_xapi_attributes.go   A

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 25
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B sqs.*SQS.XIsEmptyQueue 0 29 6
1
package sqs
2
3
import (
4
	"context"
5
	"strconv"
6
)
7
8
// XIsEmptyQueue checks if the queue does not have any message.
9
func (svc *SQS) XIsEmptyQueue(ctx context.Context, queueURL string) (bool, error) {
10
	attrList := []QueueAttributeName{
11
		QueueAttributeNameApproximateNumberOfMessages,
12
		QueueAttributeNameApproximateNumberOfMessagesDelayed,
13
		QueueAttributeNameApproximateNumberOfMessagesNotVisible,
14
	}
15
	resp, err := svc.GetQueueAttributes(ctx, GetQueueAttributesRequest{
16
		QueueURL:       queueURL,
17
		AttributeNames: attrList,
18
	})
19
	if err != nil {
20
		return false, err
21
	}
22
23
	result := resp.Attributes
24
	for _, v := range attrList {
25
		attr, ok := result[string(v)]
26
		if !ok {
27
			return false, nil
28
		}
29
		num, err := strconv.Atoi(attr)
30
		if err != nil {
31
			return false, err
32
		}
33
		if num > 0 {
34
			return false, nil
35
		}
36
	}
37
	return true, nil
38
}
39