Skip to content
Snippets Groups Projects
Commit 23b41d37 authored by Daniel Naude's avatar Daniel Naude
Browse files

Add concurrency handling to debug SQS message sending

This is to fix sqs messages with a delay not working on local development environments.
parent 8253ab8a
No related branches found
No related tags found
1 merge request!56Add concurrency handling to debug SQS message sending
...@@ -6,10 +6,12 @@ import ( ...@@ -6,10 +6,12 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
"io" "io"
"sync"
"time" "time"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
"github.com/google/uuid" "github.com/google/uuid"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/s3" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/s3"
...@@ -108,7 +110,10 @@ func (m *Messenger) SendSQSMessage(headers map[string]string, body string, curre ...@@ -108,7 +110,10 @@ func (m *Messenger) SendSQSMessage(headers map[string]string, body string, curre
func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID *string, sqsType string, isDebug bool) error { func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID *string, sqsType string, isDebug bool) error {
if isDebug { if isDebug {
var wg sync.WaitGroup
wg.Add(1)
go func() { go func() {
defer wg.Done()
if msgr.DelaySeconds != nil { if msgr.DelaySeconds != nil {
delay := *msgr.DelaySeconds delay := *msgr.DelaySeconds
time.Sleep(time.Second * time.Duration(delay)) time.Sleep(time.Second * time.Duration(delay))
...@@ -118,6 +123,7 @@ func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID * ...@@ -118,6 +123,7 @@ func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID *
Post("http://127.0.0.1:3000/sqs/" + sqsType) Post("http://127.0.0.1:3000/sqs/" + sqsType)
}() }()
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
wg.Wait()
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment