Skip to content

Commit

Permalink
feat: expiration manager commiting deletes in batches
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentegnz committed Mar 2, 2024
1 parent 07c5815 commit 20777f3
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 20777f3

Please sign in to comment.