Skip to content

Commit

Permalink
Cancel move on shutdown. This is fine because we operate in a transac…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
danielmarbach committed Oct 16, 2019
1 parent 617e508 commit 06dd620
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ async Task MoveMaturedDelayedMessages()
{
using (var transaction = connection.BeginTransaction())
{
await table.MoveMaturedMessages(batchSize, connection, transaction).ConfigureAwait(false);
await table.MoveMaturedMessages(batchSize, connection, transaction, cancellationToken).ConfigureAwait(false);
transaction.Commit();
}
}
}
catch (OperationCanceledException)
{
// Graceful shutdown
return;
}
catch (SqlException e) when (cancellationToken.IsCancellationRequested)
{
Logger.Debug("Exception thrown while performing cancellation", e);
return;
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace NServiceBus.Transport.SQLServer
{
using System;
using System.Data.SqlClient;
using System.Threading;
using System.Threading.Tasks;
using Transport;

Expand All @@ -25,12 +26,12 @@ public async Task Store(OutgoingMessage message, TimeSpan dueAfter, string desti
}
}

public async Task MoveMaturedMessages(int batchSize, SqlConnection connection, SqlTransaction transaction)
public async Task MoveMaturedMessages(int batchSize, SqlConnection connection, SqlTransaction transaction, CancellationToken cancellationToken)
{
using (var command = new SqlCommand(moveMaturedCommand, connection, transaction))
{
command.Parameters.AddWithValue("BatchSize", batchSize);
await command.ExecuteNonQueryAsync().ConfigureAwait(false);
await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false);
}
}

Expand Down

0 comments on commit 06dd620

Please sign in to comment.