Skip to content

Commit

Permalink
Throw exception when scheduled value is in the past
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Feb 1, 2021
1 parent 6eac9f3 commit fee26d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 0 additions & 2 deletions examples/InMemoryUnitTest/SampleEventConsumerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public async Task ConsumerWorksAsync()

// Get the publisher and publish the event
var publisher = provider.GetRequiredService<IEventPublisher>();
var id = Guid.NewGuid().ToString();
var processedOn = DateTimeOffset.UtcNow;
await publisher.PublishAsync(new SampleEvent
{
Make = "TESLA",
Expand Down
10 changes: 10 additions & 0 deletions src/Tingle.EventBus/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public async Task<string> PublishAsync<TEvent>(EventContext<TEvent> @event,
CancellationToken cancellationToken = default)
where TEvent : class
{
if (scheduled != null && scheduled <= DateTimeOffset.UtcNow)
{
throw new ArgumentException("Scheduled time cannot be in the past.");
}

// Instrumentation
using var activity = EventBusActivitySource.StartActivity(ActivityNames.Publish, ActivityKind.Producer);
activity?.AddTag(ActivityTagNames.EventBusEventType, typeof(TEvent).FullName);
Expand Down Expand Up @@ -128,6 +133,11 @@ public async Task<IList<string>> PublishAsync<TEvent>(IList<EventContext<TEvent>
CancellationToken cancellationToken = default)
where TEvent : class
{
if (scheduled != null && scheduled <= DateTimeOffset.UtcNow)
{
throw new ArgumentException("Scheduled time cannot be in the past.");
}

// Instrumentation
using var activity = EventBusActivitySource.StartActivity(ActivityNames.Publish, ActivityKind.Producer);
activity?.AddTag(ActivityTagNames.EventBusEventType, typeof(TEvent).FullName);
Expand Down

0 comments on commit fee26d2

Please sign in to comment.