internal void InnerPoll(CancellationToken cancellationToken)
{
var utcNow = DateTime.UtcNow;
if (NextQueryUtc > utcNow || cancellationToken.IsCancellationRequested)
{
return;
}
// connect to the data store and get all the expired timeouts
TimeoutsBatch timeoutsBatch = _processManagerFinder.GetTimeoutsBatch();
foreach (var timeoutData in timeoutsBatch.DueTimeouts)
{
if (cancellationToken.IsCancellationRequested)
{
return;
}
// dispatch the timeout message
var timeoutMsg = new TimeoutMessage(timeoutData.ProcessManagerId);
_bus.Send(timeoutData.Destination, timeoutMsg);
// remove dispatch timeout
_processManagerFinder.RemoveDispatchedTimeout(timeoutData.Id);
}
lock (_locker)
{
var nextQueryTime = timeoutsBatch.NextQueryTime;
// ensure to poll at least every minute
var maxNextQuery = utcNow.AddMinutes(1);
NextQueryUtc = (nextQueryTime > maxNextQuery) ? maxNextQuery : nextQueryTime;
Logger.DebugFormat("Polling next query is at {0}.", NextQueryUtc.ToLocalTime());
}
}
}