Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Ensure that null is sent through on DelaySeconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Im5tu committed Dec 20, 2020
1 parent 62bcfac commit 65dd6eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/OpenMessage.AWS.SQS/SqsDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ public override async Task DispatchAsync(Message<T> message, CancellationToken c
var request = new SendMessageRequest
{
MessageAttributes = GetMessageProperties(message),
DelaySeconds = DelaySeconds(message),
MessageBody = msg,
QueueUrl = _queueUrl
};

var delay = DelaySeconds(message);
if (delay.HasValue)
request.DelaySeconds = delay.Value;

#if NETCOREAPP3_1
var stopwatch = OpenMessageEventSource.Instance.ProcessMessageDispatchStart();
#endif
Expand All @@ -89,14 +92,14 @@ public override async Task DispatchAsync(Message<T> message, CancellationToken c
}
}

private static int DelaySeconds(Message<T> message)
private static int? DelaySeconds(Message<T> message)
{
if (message is ISupportSendDelay delay && delay.SendDelay > TimeSpan.Zero)
{
return Math.Min(MaximumSqsDelaySeconds, (int) delay.SendDelay.TotalSeconds);
}

return 0;
return null;
}

private Dictionary<string, MessageAttributeValue> GetMessageProperties(Message<T> message)
Expand Down
4 changes: 2 additions & 2 deletions src/OpenMessage.AWS.SQS/SqsDispatcherService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Channels;
Expand Down Expand Up @@ -138,7 +138,7 @@ private async Task ProcessMessages(List<SendSqsMessageCommand> messages)

var response = await client.SendMessageBatchAsync(request);

// TODO :: we should be able to complete certain messages here
// TODO :: Complete elements in the batch that we can
if (response.Failed.Count > 0)
Throw.Exception("One or more messages failed to send");

Expand Down

0 comments on commit 65dd6eb

Please sign in to comment.