Skip to content

Commit

Permalink
Merge pull request #349 from vicentegnz-contributions/feat/expiration…
Browse files Browse the repository at this point in the history
…-manager-commiting-deletes-in-batches

feat: expiration manager commiting deletes in batches
  • Loading branch information
azygis committed Mar 2, 2024
2 parents 07c5815 + 20777f3 commit ffb9352
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Hangfire.PostgreSql/ExpirationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public void Execute(CancellationToken cancellationToken)
_logger.DebugFormat("Removing outdated records from table '{0}'...", table);

UseConnectionDistributedLock(_storage, connection => {
using IDbTransaction transaction = connection.BeginTransaction();
int removedCount;
do
{
using IDbTransaction transaction = connection.BeginTransaction();
removedCount = connection.Execute($@"
DELETE FROM ""{_storage.Options.SchemaName}"".""{table}""
WHERE ""id"" IN (
Expand All @@ -95,14 +95,13 @@ DELETE FROM ""{_storage.Options.SchemaName}"".""{table}""
continue;
}
transaction.Commit();
_logger.InfoFormat("Removed {0} outdated record(s) from '{1}' table.", removedCount, table);
cancellationToken.WaitHandle.WaitOne(_delayBetweenPasses);
cancellationToken.ThrowIfCancellationRequested();
}
while (removedCount != 0);
transaction.Commit();
});
}

Expand Down

0 comments on commit ffb9352

Please sign in to comment.