From 933aa3bf976f66d2a184922aff613c2b22fdca1b Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 23 Sep 2019 16:38:34 +0100 Subject: Move the sqs stuff out to aws.go --- bookpipeline/aws.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'bookpipeline/aws.go') diff --git a/bookpipeline/aws.go b/bookpipeline/aws.go index 4d32f3d..689f1b2 100644 --- a/bookpipeline/aws.go +++ b/bookpipeline/aws.go @@ -165,6 +165,21 @@ func (a *AwsConn) QueueHeartbeat(msg Qmsg, qurl string, duration int64) (Qmsg, e return Qmsg{}, nil } +// GetQueueDetails gets the number of in progress and available +// messages for a queue. These are returned as strings. +func (a *AwsConn) GetQueueDetails(url string) (string, string, error) { + numAvailable := "ApproximateNumberOfMessages" + numInProgress := "ApproximateNumberOfMessagesNotVisible" + attrs, err := a.sqssvc.GetQueueAttributes(&sqs.GetQueueAttributesInput{ + AttributeNames: []*string{&numAvailable, &numInProgress}, + QueueUrl: &url, + }) + if err != nil { + return "", "", errors.New(fmt.Sprintf("Failed to get queue attributes: %s", err)) + } + return *attrs.Attributes[numAvailable], *attrs.Attributes[numInProgress], nil +} + func (a *AwsConn) PreQueueId() string { return a.prequrl } -- cgit v1.2.1-24-ge1ad