From 9840edb21ab1bca093001d81c510910bb00c73d4 Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 17 Oct 2019 16:48:00 +0100 Subject: Adjust the heartbeat searching function to hopefully have better luck at finding it and not letting another process steal it. --- aws.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'aws.go') diff --git a/aws.go b/aws.go index 5a037ff..5d66178 100644 --- a/aws.go +++ b/aws.go @@ -17,7 +17,7 @@ import ( ) const PreprocPattern = `_bin[0-9].[0-9].png` -const heartbeatRetry = 10 +const heartbeatRetry = 20 type Qmsg struct { Id, Handle, Body string @@ -157,9 +157,6 @@ func (a *AwsConn) QueueHeartbeat(msg Qmsg, qurl string, duration int64) (Qmsg, e if ok && aerr.Code() == "InvalidParameterValue" { // Try heartbeatRetry times to find the message for range [heartbeatRetry]bool{} { - // Wait a little in case existing visibilitytimeout needs to expire - time.Sleep((time.Duration(duration) / heartbeatRetry) * time.Second) - msgResult, err := a.sqssvc.ReceiveMessage(&sqs.ReceiveMessageInput{ MaxNumberOfMessages: aws.Int64(10), VisibilityTimeout: &duration, @@ -178,6 +175,8 @@ func (a *AwsConn) QueueHeartbeat(msg Qmsg, qurl string, duration int64) (Qmsg, e }, nil } } + // Wait a little in case existing visibilitytimeout needs to expire + time.Sleep((2 * time.Duration(duration) / heartbeatRetry) * time.Second) } return Qmsg{}, errors.New("Heartbeat error failed to find message to update heartbeat") } else { -- cgit v1.2.1-24-ge1ad