Skip to content

Commit 53afcdf

Browse files
authored
Merge pull request #36 from raisedapp/develop
Version 0.30
2 parents 567cd0f + 0d78ef8 commit 53afcdf

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

src/main/Hangfire.Storage.SQLite/ExpirationManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Hangfire.Storage.SQLite
99
{
1010
/// <summary>
11-
/// Represents Hangfire expiration manager for LiteDB database
11+
/// Represents Hangfire expiration manager for SQLite database
1212
/// </summary>
1313
#pragma warning disable CS0618
1414
public class ExpirationManager : IBackgroundProcess, IServerComponent
@@ -44,7 +44,7 @@ public class ExpirationManager : IBackgroundProcess, IServerComponent
4444
/// <summary>
4545
/// Constructs expiration manager with one hour checking interval
4646
/// </summary>
47-
/// <param name="storage">LiteDb storage</param>
47+
/// <param name="storage">SQLite storage</param>
4848
public ExpirationManager(SQLiteStorage storage)
4949
: this(storage, TimeSpan.FromHours(1))
5050
{
@@ -53,7 +53,7 @@ public ExpirationManager(SQLiteStorage storage)
5353
/// <summary>
5454
/// Constructs expiration manager with specified checking interval
5555
/// </summary>
56-
/// <param name="storage">LiteDB storage</param>
56+
/// <param name="storage">SQLite storage</param>
5757
/// <param name="checkInterval">Checking interval</param>
5858
public ExpirationManager(SQLiteStorage storage, TimeSpan checkInterval)
5959
{

src/main/Hangfire.Storage.SQLite/Hangfire.Storage.SQLite.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
88
</PropertyGroup>
99
<PropertyGroup>
10-
<Version>0.2.6</Version>
10+
<Version>0.3.0</Version>
1111
<Authors>RaisedApp</Authors>
1212
<Company>RaisedApp</Company>
1313
<Copyright>Copyright © 2019 - Present</Copyright>
@@ -20,7 +20,7 @@
2020
<title>Hangfire Storage SQLite</title>
2121
<Description>An Alternative SQLite Storage for Hangfire</Description>
2222
<PackageReleaseNotes>
23-
0.2.6
23+
0.3.0
2424
- Fix DistributedLockTimeoutException with Hangfire.Storage.SQLite
2525
</PackageReleaseNotes>
2626
</PropertyGroup>

src/main/Hangfire.Storage.SQLite/HangfireDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class HangfireDbContext
3535

3636

3737
/// <summary>
38-
/// Starts LiteDB database using a connection string for file system database
38+
/// Starts SQLite database using a connection string for file system database
3939
/// </summary>
4040
/// <param name="databasePath">the database path</param>
4141
/// <param name="prefix">Table prefix</param>

src/main/Hangfire.Storage.SQLite/SQLiteDistributedLock.cs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public SQLiteDistributedLock(string resource, TimeSpan timeout, HangfireDbContex
7070
/// <summary>
7171
/// Disposes the object
7272
/// </summary>
73-
/// <exception cref="LiteDbDistributedLockException"></exception>
73+
/// <exception cref="DistributedLockTimeoutException"></exception>
7474
public void Dispose()
7575
{
7676
if (_completed)
@@ -117,26 +117,31 @@ private void Acquire(TimeSpan timeout)
117117

118118
while (!isLockAcquired && (lockTimeoutTime >= now))
119119
{
120-
var result = _dbContext.DistributedLockRepository.FirstOrDefault(_ => _.Resource == _resource);
121-
var distributedLock = result ?? new DistributedLock();
120+
DistributedLock result;
122121

123-
if (string.IsNullOrWhiteSpace(distributedLock.Id))
124-
distributedLock.Id = Guid.NewGuid().ToString();
122+
lock (EventWaitHandleName)
123+
{
124+
result = _dbContext.DistributedLockRepository.FirstOrDefault(_ => _.Resource == _resource);
125+
var distributedLock = result ?? new DistributedLock();
125126

126-
distributedLock.Resource = _resource;
127-
distributedLock.ExpireAt = DateTime.UtcNow.Add(_storageOptions.DistributedLockLifetime);
127+
if (string.IsNullOrWhiteSpace(distributedLock.Id))
128+
distributedLock.Id = Guid.NewGuid().ToString();
128129

129-
var rowsAffected = _dbContext.Database.Update(distributedLock);
130-
if (rowsAffected == 0)
131-
{
132-
try
133-
{
134-
_dbContext.Database.Insert(distributedLock);
135-
}
136-
catch(SQLiteException e) when (e.Result == SQLite3.Result.Constraint)
130+
distributedLock.Resource = _resource;
131+
distributedLock.ExpireAt = DateTime.UtcNow.Add(_storageOptions.DistributedLockLifetime);
132+
133+
var rowsAffected = _dbContext.Database.Update(distributedLock);
134+
if (rowsAffected == 0)
137135
{
138-
// The lock already exists preventing us from inserting.
139-
continue;
136+
try
137+
{
138+
_dbContext.Database.Insert(distributedLock);
139+
}
140+
catch (SQLiteException e) when (e.Result == SQLite3.Result.Constraint)
141+
{
142+
// The lock already exists preventing us from inserting.
143+
continue;
144+
}
140145
}
141146
}
142147

src/samples/ConsoleSample/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void Main(string[] args)
1010
{
1111
try
1212
{
13-
// you can use LiteDB Storage and specify the connection string name
13+
// you can use SQLite Storage and specify the connection string name
1414
GlobalConfiguration.Configuration
1515
.UseColouredConsoleLogProvider()
1616
.UseSQLiteStorage();
@@ -28,7 +28,7 @@ public static void Main(string[] args)
2828
}
2929
catch (Exception ex)
3030
{
31-
Console.WriteLine($"Error in execution. Detail: {ex.ToString()}");
31+
Console.WriteLine($"Error in execution. Detail: {ex}");
3232
}
3333

3434
Console.ReadLine();

0 commit comments

Comments
 (0)