Skip to content

Commit

Permalink
Use TimeSpan instead of milliseconds int (#3292)
Browse files Browse the repository at this point in the history
* Use TimeSpan instead of milisecond int

Feature #3220

* Fix Extensions

* Fix SQL Timestamp mapping

* Address Comments
  • Loading branch information
preardon authored Sep 3, 2024
1 parent 6ce26a8 commit 2f68e3c
Show file tree
Hide file tree
Showing 72 changed files with 260 additions and 260 deletions.
2 changes: 1 addition & 1 deletion samples/TaskQueue/RMQTaskQueue/GreetingsSender/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void Main(string[] args)
{
configure.ProducerRegistry = producerRegistry;
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
})
.AutoFromAssemblies();

Expand Down
2 changes: 1 addition & 1 deletion samples/WebAPI/WebAPI_Dapper/GreetingsWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void ConfigureBrighter(IServiceCollection services)
configure.TransactionProvider = makeOutbox.transactionProvider;
configure.ConnectionProvider = makeOutbox.connectionProvider;
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
})
.AutoFromAssemblies(typeof(AddPersonHandlerAsync).Assembly);
}
Expand Down
4 changes: 2 additions & 2 deletions samples/WebAPI/WebAPI_Dapper/Greetings_Sweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@
configure.TransactionProvider = makeOutbox.transactionProvider;
configure.ConnectionProvider = makeOutbox.connectionProvider;
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
})
.UseOutboxSweeper(options =>
{
options.TimerInterval = 3;
options.MinimumMessageAge = 1000;
options.MinimumMessageAge = TimeSpan.FromSeconds(1);
options.BatchSize = 10;
options.UseBulk = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void ConfigureBrighter(HostBuilderContext hostContext, IServiceCollection
config.ConnectionProvider = makeOutbox.connectionProvider;
config.TransactionProvider = makeOutbox.transactionProvider;
config.MaxOutStandingMessages = 5;
config.MaxOutStandingCheckIntervalMilliSeconds = 500;
config.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
})
.AutoFromAssemblies();

Expand Down
4 changes: 2 additions & 2 deletions samples/WebAPI/WebAPI_Dapper/Salutation_Sweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@
configure.TransactionProvider = makeOutbox.transactionProvider;
configure.ConnectionProvider = makeOutbox.connectionProvider;
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
})
.UseOutboxSweeper(options =>
{
options.TimerInterval = 3;
options.MinimumMessageAge = 1000;
options.MinimumMessageAge = TimeSpan.FromSeconds(1);
options.BatchSize = 10;
options.UseBulk = false;
});
Expand Down
2 changes: 1 addition & 1 deletion samples/WebAPI/WebAPI_Dynamo/GreetingsWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void ConfigureBrighter(IServiceCollection services)
configure.ConnectionProvider = typeof(DynamoDbUnitOfWork);
configure.TransactionProvider = typeof(DynamoDbUnitOfWork);
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
configure.OutBoxBag = new Dictionary<string, object> { { "Topic", "GreetingMade" } };
})
.AutoFromAssemblies(typeof(AddPersonHandlerAsync).Assembly);
Expand Down
2 changes: 1 addition & 1 deletion samples/WebAPI/WebAPI_Dynamo/Greetings_Sweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
configure.ConnectionProvider = typeof(DynamoDbUnitOfWork);
configure.TransactionProvider = typeof(DynamoDbUnitOfWork);
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
configure.OutBoxBag = new Dictionary<string, object> { { "Topic", "GreetingMade" } };
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void ConfigureBrighter(
configure.ConnectionProvider = typeof(DynamoDbUnitOfWork);
configure.TransactionProvider = typeof(DynamoDbUnitOfWork);
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
}
)
.AutoFromAssemblies();
Expand Down
2 changes: 1 addition & 1 deletion samples/WebAPI/WebAPI_EFCore/GreetingsWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void ConfigureBrighter(IServiceCollection services)
configure.TransactionProvider = transactionProvider;
configure.ConnectionProvider = connectionProvider;
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
}
)
.AutoFromAssemblies();
Expand Down
2 changes: 1 addition & 1 deletion samples/WebAPI/WebAPI_EFCore/Greetings_Sweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
configure.TransactionProvider = makeOutbox.transactionProvider;
configure.ConnectionProvider = makeOutbox.connectionProvider;
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
});

WebApplication app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void ConfigureBrighter(HostBuilderContext hostContext, IServiceCollection
configure.TransactionProvider = makeOutbox.transactionProvider;
configure.ConnectionProvider = makeOutbox.connectionProvider;
configure.MaxOutStandingMessages = 5;
configure.MaxOutStandingCheckIntervalMilliSeconds = 500;
configure.MaxOutStandingCheckInterval = TimeSpan.FromMilliseconds(500);
})
.AutoFromAssemblies();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private static IAmAnExternalBusService BuildExternalBus(IServiceProvider service
RequestContextFactory(serviceProvider),
busConfiguration.OutboxTimeout,
busConfiguration.MaxOutStandingMessages,
busConfiguration.MaxOutStandingCheckIntervalMilliSeconds,
busConfiguration.MaxOutStandingCheckInterval,
busConfiguration.OutBoxBag,
busConfiguration.ArchiveBatchSize,
busConfiguration.InstrumentationOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ THE SOFTWARE. */

#endregion

using System;

namespace Paramore.Brighter.Extensions.Hosting
{
public class TimedOutboxArchiverOptions
Expand All @@ -34,6 +36,6 @@ public class TimedOutboxArchiverOptions
/// <summary>
/// The minimum age in hours to Archive
/// </summary>
public int MinimumAge { get; set; } = 24;
public TimeSpan MinimumAge { get; set; } = TimeSpan.FromHours(24);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void Sweep(object state)
IAmACommandProcessor commandProcessor = scope.ServiceProvider.GetService<IAmACommandProcessor>();

var outBoxSweeper = new OutboxSweeper(
millisecondsSinceSent: _options.MinimumMessageAge,
timeSinceSent: _options.MinimumMessageAge,
commandProcessor: commandProcessor,
new InMemoryRequestContextFactory(),
_options.BatchSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ THE SOFTWARE. */

#endregion

using System;
using System.Collections.Generic;

namespace Paramore.Brighter.Extensions.Hosting
Expand All @@ -38,7 +39,7 @@ public class TimedOutboxSweeperOptions
/// <summary>
/// The age a message to pickup by the sweeper in milliseconds.
/// </summary>
public int MinimumMessageAge { get; set; } = 5000;
public TimeSpan MinimumMessageAge { get; set; } = TimeSpan.FromSeconds(5);

/// <summary>
/// The maximum number of messages to dispatch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Headers Build(Message message)
};

if (message.Header.TimeStamp != default)
headers.Add(HeaderNames.TIMESTAMP, new DateTimeOffset(message.Header.TimeStamp).ToString().ToByteArray());
headers.Add(HeaderNames.TIMESTAMP, message.Header.TimeStamp.ToString().ToByteArray());
else
headers.Add(HeaderNames.TIMESTAMP, DateTimeOffset.UtcNow.ToString().ToByteArray());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void RequeueMessage(Message message, string queueName, int delayMilliseco
message.Body.Bytes);
}

private IBasicProperties CreateBasicProperties(string id, DateTime timeStamp, string type, string contentType,
private IBasicProperties CreateBasicProperties(string id, DateTimeOffset timeStamp, string type, string contentType,
string replyTo, bool persistMessage, IDictionary<string, object> headers = null)
{
var basicProperties = _channel.CreateBasicProperties();
Expand All @@ -186,7 +186,7 @@ private IBasicProperties CreateBasicProperties(string id, DateTime timeStamp, st
basicProperties.ContentType = contentType;
basicProperties.Type = type;
basicProperties.MessageId = id;
basicProperties.Timestamp = new AmqpTimestamp(UnixTimestamp.GetUnixTimestampSeconds(timeStamp));
basicProperties.Timestamp = new AmqpTimestamp(UnixTimestamp.GetUnixTimestampSeconds(timeStamp.DateTime));
if (!string.IsNullOrEmpty(replyTo))
basicProperties.ReplyTo = replyTo;

Expand Down
Loading

0 comments on commit 2f68e3c

Please sign in to comment.