-
-
Notifications
You must be signed in to change notification settings - Fork 223
Add sync way to retry in InlineSendingAgent #1614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -20,16 +20,18 @@ public InlineSendingAgent(ILogger logger, ISender sender, Endpoint endpoint, IMe | |||
_settings = settings; | |||
Endpoint = endpoint; | |||
|
|||
if (endpoint.TelemetryEnabled) | |||
if (settings.UseSyncRetryBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use optional property to switch to different behavior so no breaking change is added
/// Abstract a way we can retry on <typeparamref name="T"/> message | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
internal interface IRetryBlock<T> : IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abstraction for retry logic
|
||
Post(message); | ||
|
||
return _block.Completion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this version we are returning Task from ActionBlock
await _handler.ExecuteAsync(item.Message, _cancellationToken); | ||
_logger.LogDebug("Completed {Item}", item.Message); | ||
|
||
_block.Complete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Success
/// When this option is enabled retry block used in InlineSendingAgent will synchronously wait on sending task to assure the message is send. | ||
/// When set to <see langword="false"/> default behavior is used so InlineSendingAgent agent will try to send a message and when failed it will give control to caller and retry on other thread in async manner | ||
/// </summary> | ||
public bool UseSyncRetryBlock { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option to drive sending agent
private readonly CancellationToken _cancellationToken = cancellationToken; | ||
private readonly Func<T, CancellationToken, Task> _handler = handler; | ||
private readonly ILogger _logger = logger; | ||
public TimeSpan[] Pauses { get; set; } = [0.Milliseconds(), 50.Milliseconds(), 100.Milliseconds(), 250.Milliseconds()]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this Pauses to DurabilitySettings so retry logic could be configurable?
420ed6a
to
4bae351
Compare
public ISender Sender { get; } | ||
|
||
private async Task sendWithTracing(Envelope e, CancellationToken cancellationToken) | ||
{ | ||
using var activity = WolverineTracing.StartSending(e); | ||
try | ||
{ | ||
//TODO: What about cancellationToken?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cancellationToken is not passed to Sender.SendAsync - I think it should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't make sense before when it was truly asynchronous
No description provided.