public async Task Execute(SqlConnection conn, ISchedulingAgent agent) { if (!await conn.TryGetGlobalLock(OutgoingMessageLockId)) { return; } try { var destinations = await FindAllOutgoingDestinations(conn); var count = 0; foreach (var destination in destinations) { var found = await recoverFrom(destination, conn); count += found; } var wasMaxedOut = count >= _settings.Retries.RecoveryBatchSize; if (wasMaxedOut) { agent.RescheduleOutgoingRecovery(); } } finally { await conn.ReleaseGlobalLock(OutgoingMessageLockId); } }
public async Task Execute(IDocumentSession session, ISchedulingAgent agent) { if (!await session.TryGetGlobalTxLock(OutgoingMessageLockId)) { return; } var destinations = await FindAllOutgoingDestinations(session); var count = 0; foreach (var destination in destinations) { count += await recoverFrom(destination, session); } var wasMaxedOut = count >= _settings.Retries.RecoveryBatchSize; if (wasMaxedOut) { agent.RescheduleOutgoingRecovery(); } }