Skip to content

Commit f07e3d6

Browse files
committed
Changed method name; updated some packages
1 parent b59cd66 commit f07e3d6

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Hangfire.PostgreSql/Hangfire.PostgreSql.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
<ItemGroup>
3232
<PackageReference Include="Dapper" Version="2.0.123" />
33-
<PackageReference Include="GitVersion.MsBuild" Version="5.8.1">
33+
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1">
3434
<PrivateAssets>all</PrivateAssets>
3535
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3636
</PackageReference>
37-
<PackageReference Include="Hangfire.Core" Version="1.7.27" />
37+
<PackageReference Include="Hangfire.Core" Version="1.7.28" />
3838
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
3939
</ItemGroup>
4040

src/Hangfire.PostgreSql/PostgreSqlDistributedLock.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using System.Threading;
2626
using System.Transactions;
2727
using Dapper;
28+
using Hangfire.Annotations;
2829
using Hangfire.Logging;
2930
using Npgsql;
3031
using IsolationLevel = System.Data.IsolationLevel;
@@ -126,7 +127,7 @@ public static void Lock(string resource, TimeSpan timeout, IDbConnection connect
126127
IDbTransaction trx = null;
127128
try
128129
{
129-
TryBeginTransaction(connection, out trx);
130+
trx = BeginTransactionIfNotPresent(connection);
130131

131132
int rowsAffected = connection.Execute($@"
132133
INSERT INTO ""{options.SchemaName}"".""lock""(""resource"", ""acquired"")
@@ -189,7 +190,7 @@ private static void TryRemoveLock(string resource, IDbConnection connection, Pos
189190
IDbTransaction trx = null;
190191
try
191192
{
192-
TryBeginTransaction(connection, out trx);
193+
trx = BeginTransactionIfNotPresent(connection);
193194
connection.Execute($@"DELETE FROM ""{options.SchemaName}"".""lock"" WHERE ""resource"" = @Resource AND ""acquired"" < @Timeout",
194195
new {
195196
Resource = resource,
@@ -208,11 +209,12 @@ private static void TryRemoveLock(string resource, IDbConnection connection, Pos
208209
}
209210
}
210211

211-
private static void TryBeginTransaction(IDbConnection connection, out IDbTransaction trx)
212+
[CanBeNull]
213+
private static IDbTransaction BeginTransactionIfNotPresent(IDbConnection connection)
212214
{
213215
// If transaction scope was created outside of hangfire, the newly-opened connection is automatically enlisted into the transaction.
214216
// Starting a new transaction throws "A transaction is already in progress; nested/concurrent transactions aren't supported." in that case.
215-
trx = Transaction.Current == null ? connection.BeginTransaction(IsolationLevel.ReadCommitted) : null;
217+
return Transaction.Current == null ? connection.BeginTransaction(IsolationLevel.ReadCommitted) : null;
216218
}
217219
}
218220

0 commit comments

Comments
 (0)