-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
14 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,42 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Paramore.Brighter | ||
namespace Paramore.Brighter | ||
{ | ||
public class OutboxSweeper | ||
{ | ||
private readonly int _milliSecondsSinceSent; | ||
private readonly int _millisecondsSinceSent; | ||
private readonly IAmACommandProcessor _commandProcessor; | ||
private readonly int _batchSize; | ||
private readonly bool _useBulk; | ||
|
||
/// <summary> | ||
/// This sweeper clears an outbox of any outstanding messages within the time interval | ||
/// </summary> | ||
/// <param name="milliSecondsSinceSent">How long can a message sit in the box before we attempt to resend</param> | ||
/// <param name="millisecondsSinceSent">How long can a message sit in the box before we attempt to resend</param> | ||
/// <param name="commandProcessor">Who should post the messages</param> | ||
/// <param name="batchSize">The maximum number of messages to dispatch.</param> | ||
/// <param name="useBulk">Use the producers bulk dispatch functionality.</param> | ||
public OutboxSweeper(int milliSecondsSinceSent, IAmACommandProcessor commandProcessor, int batchSize = 100, | ||
public OutboxSweeper(int millisecondsSinceSent, IAmACommandProcessor commandProcessor, int batchSize = 100, | ||
bool useBulk = false) | ||
{ | ||
_milliSecondsSinceSent = milliSecondsSinceSent; | ||
_millisecondsSinceSent = millisecondsSinceSent; | ||
_commandProcessor = commandProcessor; | ||
_batchSize = batchSize; | ||
_useBulk = useBulk; | ||
} | ||
|
||
/// <summary> | ||
/// Dispatches the oldest un-dispatched messages from the outbox in a background thread. | ||
/// </summary> | ||
public void Sweep() | ||
{ | ||
_commandProcessor.ClearOutbox(_batchSize, _milliSecondsSinceSent); | ||
} | ||
|
||
public Task SweepAsync(CancellationToken cancellationToken = default) | ||
{ | ||
_commandProcessor.ClearAsyncOutbox(_batchSize, _milliSecondsSinceSent, _useBulk); | ||
|
||
return Task.CompletedTask; | ||
_commandProcessor.ClearOutbox(_batchSize, _millisecondsSinceSent); | ||
} | ||
|
||
/// <summary> | ||
/// Dispatches the oldest un-dispatched messages from the asynchronous outbox in a background thread. | ||
/// </summary> | ||
public void SweepAsyncOutbox() | ||
{ | ||
_commandProcessor.ClearAsyncOutbox(_batchSize, _milliSecondsSinceSent, _useBulk); | ||
_commandProcessor.ClearAsyncOutbox(_batchSize, _millisecondsSinceSent, _useBulk); | ||
} | ||
} | ||
} |