Skip to content

Commit ffb9352

Browse files
authored
Merge pull request #349 from vicentegnz-contributions/feat/expiration-manager-commiting-deletes-in-batches
feat: expiration manager commiting deletes in batches
2 parents 07c5815 + 20777f3 commit ffb9352

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/Hangfire.PostgreSql/ExpirationManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public void Execute(CancellationToken cancellationToken)
7777
_logger.DebugFormat("Removing outdated records from table '{0}'...", table);
7878

7979
UseConnectionDistributedLock(_storage, connection => {
80-
using IDbTransaction transaction = connection.BeginTransaction();
8180
int removedCount;
8281
do
8382
{
83+
using IDbTransaction transaction = connection.BeginTransaction();
8484
removedCount = connection.Execute($@"
8585
DELETE FROM ""{_storage.Options.SchemaName}"".""{table}""
8686
WHERE ""id"" IN (
@@ -95,14 +95,13 @@ DELETE FROM ""{_storage.Options.SchemaName}"".""{table}""
9595
continue;
9696
}
9797

98+
transaction.Commit();
9899
_logger.InfoFormat("Removed {0} outdated record(s) from '{1}' table.", removedCount, table);
99100

100101
cancellationToken.WaitHandle.WaitOne(_delayBetweenPasses);
101102
cancellationToken.ThrowIfCancellationRequested();
102103
}
103104
while (removedCount != 0);
104-
105-
transaction.Commit();
106105
});
107106
}
108107

0 commit comments

Comments
 (0)