Skip to content

Add sync way to retry in InlineSendingAgent#1614

Merged
jeremydmiller merged 2 commits intoJasperFx:mainfrom
dominikjeske:features/retry_sync
Aug 6, 2025
Merged

Add sync way to retry in InlineSendingAgent#1614
jeremydmiller merged 2 commits intoJasperFx:mainfrom
dominikjeske:features/retry_sync

Conversation

@dominikjeske
Copy link
Contributor

No description provided.

Endpoint = endpoint;

if (endpoint.TelemetryEnabled)
if (settings.UseSyncRetryBlock)
Copy link
Contributor Author

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
Copy link
Contributor Author

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;
Copy link
Contributor Author

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();
Copy link
Contributor Author

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; }
Copy link
Contributor Author

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()];
Copy link
Contributor Author

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?

using var activity = WolverineTracing.StartSending(e);
try
{
//TODO: What about cancellationToken??
Copy link
Contributor Author

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

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants