Skip to content

Commit c69d5de

Browse files
authored
Merge pull request #15 from raisedapp/develop
Version 0.2.1
2 parents 361a97f + fc02021 commit c69d5de

8 files changed

Lines changed: 43 additions & 9 deletions

File tree

src/main/Hangfire.Storage.SQLite/Entities/JobParameter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ public class JobParameter
2020

2121
[MaxLength(DefaultValues.MaxLengthVarCharColumn)]
2222
public string Value { get; set; }
23+
24+
[Indexed(Name = "IX_JobParameter_ExpireAt", Order = 3, Unique = false)]
25+
public DateTime ExpireAt { get; set; } = DateTime.MinValue;
2326
}
2427
}

src/main/Hangfire.Storage.SQLite/Entities/State.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ public class State
2424

2525
[MaxLength(DefaultValues.MaxLengthVarCharColumn)]
2626
public string Data { get; set; }
27+
28+
[Indexed(Name = "IX_State_ExpireAt", Order = 2, Unique = false)]
29+
public DateTime ExpireAt { get; set; } = DateTime.MinValue;
2730
}
2831
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class ExpirationManager : IBackgroundProcess, IServerComponent
3434
DefaultValues.HangfireListTblName,
3535
DefaultValues.SetTblName,
3636
DefaultValues.HashTblName,
37+
DefaultValues.StateTblName,
38+
DefaultValues.JobParameterTblName
3739
};
3840

3941
private static readonly ILog Logger = LogProvider.For<ExpirationManager>();

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

Lines changed: 4 additions & 4 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.0</Version>
10+
<Version>0.2.1</Version>
1111
<Authors>RaisedApp</Authors>
1212
<Company>RaisedApp</Company>
1313
<Copyright>Copyright © 2019 - Present</Copyright>
@@ -20,9 +20,9 @@
2020
<title>Hangfire Storage SQLite</title>
2121
<Description>An Alternative SQLite Storage for Hangfire</Description>
2222
<PackageReleaseNotes>
23-
0.2.0
24-
- Distributed Lock In ExpirationManager
25-
- ExpireAt In JobDetails Method
23+
0.2.1
24+
- Add AutoVacuum Options
25+
- Add ExpireAt In JobParamter And State Models
2626
</PackageReleaseNotes>
2727
</PropertyGroup>
2828
<ItemGroup>

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Hangfire.Storage.SQLite.Entities;
1+
using Hangfire.Logging;
2+
using Hangfire.Storage.SQLite.Entities;
23
using Newtonsoft.Json;
34
using SQLite;
45
using System;
@@ -12,7 +13,7 @@ namespace Hangfire.Storage.SQLite
1213
/// </summary>
1314
public class HangfireDbContext
1415
{
15-
private readonly string _prefix;
16+
private readonly ILog Logger = LogProvider.For<HangfireDbContext>();
1617

1718
/// <summary>
1819
///
@@ -106,6 +107,15 @@ public void Init(SQLiteStorageOptions storageOptions)
106107
SetRepository = Database.Table<Set>();
107108
StateRepository = Database.Table<State>();
108109
DistributedLockRepository = Database.Table<DistributedLock>();
110+
111+
try
112+
{
113+
Database.Execute($"PRAGMA auto_vacuum = {(int) storageOptions.AutoVacuumSelected};");
114+
}
115+
catch (Exception ex)
116+
{
117+
Logger.Log(LogLevel.Error, () => $"Error set auto vacuum mode. Details: {ex.ToString()}");
118+
}
109119
}
110120

111121
public TableQuery<AggregatedCounter> AggregatedCounterRepository { get; private set; }

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,17 @@ public TimeSpan DistributedLockLifetime
9595
/// Counters interval
9696
/// </summary>
9797
public TimeSpan CountersAggregateInterval { get; set; }
98+
99+
/// <summary>
100+
/// Set AutoVacuum Mode In SQLite
101+
/// </summary>
102+
public AutoVacuum AutoVacuumSelected { get; set; } = AutoVacuum.NONE;
103+
104+
public enum AutoVacuum
105+
{
106+
NONE = 0,
107+
FULL = 1,
108+
INCREMENTAL = 2
109+
}
98110
}
99111
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,15 @@ public override void ExpireJob(string jobId, TimeSpan expireIn)
168168
{
169169
var iJobId = int.Parse(jobId);
170170
var job = _.HangfireJobRepository.FirstOrDefault(x => x.Id == iJobId);
171-
171+
172172
if (job != null)
173173
{
174-
job.ExpireAt = DateTime.UtcNow.Add(expireIn);
174+
var expireAt = DateTime.UtcNow.Add(expireIn);
175+
job.ExpireAt = expireAt;
176+
175177
_.Database.Update(job);
178+
_.Database.Execute($"UPDATE [{DefaultValues.StateTblName}] SET ExpireAt = {expireAt.Ticks} WHERE JobId = {jobId}");
179+
_.Database.Execute($"UPDATE [{DefaultValues.JobParameterTblName}] SET ExpireAt = {expireAt.Ticks} WHERE JobId = {jobId}");
176180
}
177181
});
178182
}

src/test/Hangfire.Storage.SQLite.Test/SQLiteDistributedLockFacts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void Ctor_WaitForLock_OnlySingleLockCanBeAcquired()
165165

166166
manualResetEvent.Set();
167167

168-
threads.ForEach(t => Assert.True(t.Join(TimeSpan.FromSeconds(90)), "Thread is hanging unexpected"));
168+
threads.ForEach(t => Assert.True(t.Join(TimeSpan.FromSeconds(120)), "Thread is hanging unexpected"));
169169

170170
// All the threads should report success.
171171
Interlocked.MemoryBarrier();

0 commit comments

Comments
 (0)