Skip to content

Commit

Permalink
Merge pull request #15 from raisedapp/develop
Browse files Browse the repository at this point in the history
Version 0.2.1
  • Loading branch information
felixclase authored Dec 23, 2019
2 parents 361a97f + fc02021 commit c69d5de
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/main/Hangfire.Storage.SQLite/Entities/JobParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ public class JobParameter

[MaxLength(DefaultValues.MaxLengthVarCharColumn)]
public string Value { get; set; }

[Indexed(Name = "IX_JobParameter_ExpireAt", Order = 3, Unique = false)]
public DateTime ExpireAt { get; set; } = DateTime.MinValue;
}
}
3 changes: 3 additions & 0 deletions src/main/Hangfire.Storage.SQLite/Entities/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ public class State

[MaxLength(DefaultValues.MaxLengthVarCharColumn)]
public string Data { get; set; }

[Indexed(Name = "IX_State_ExpireAt", Order = 2, Unique = false)]
public DateTime ExpireAt { get; set; } = DateTime.MinValue;
}
}
2 changes: 2 additions & 0 deletions src/main/Hangfire.Storage.SQLite/ExpirationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class ExpirationManager : IBackgroundProcess, IServerComponent
DefaultValues.HangfireListTblName,
DefaultValues.SetTblName,
DefaultValues.HashTblName,
DefaultValues.StateTblName,
DefaultValues.JobParameterTblName
};

private static readonly ILog Logger = LogProvider.For<ExpirationManager>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<Version>0.2.0</Version>
<Version>0.2.1</Version>
<Authors>RaisedApp</Authors>
<Company>RaisedApp</Company>
<Copyright>Copyright © 2019 - Present</Copyright>
Expand All @@ -20,9 +20,9 @@
<title>Hangfire Storage SQLite</title>
<Description>An Alternative SQLite Storage for Hangfire</Description>
<PackageReleaseNotes>
0.2.0
- Distributed Lock In ExpirationManager
- ExpireAt In JobDetails Method
0.2.1
- Add AutoVacuum Options
- Add ExpireAt In JobParamter And State Models
</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
Expand Down
14 changes: 12 additions & 2 deletions src/main/Hangfire.Storage.SQLite/HangfireDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hangfire.Storage.SQLite.Entities;
using Hangfire.Logging;
using Hangfire.Storage.SQLite.Entities;
using Newtonsoft.Json;
using SQLite;
using System;
Expand All @@ -12,7 +13,7 @@ namespace Hangfire.Storage.SQLite
/// </summary>
public class HangfireDbContext
{
private readonly string _prefix;
private readonly ILog Logger = LogProvider.For<HangfireDbContext>();

/// <summary>
///
Expand Down Expand Up @@ -106,6 +107,15 @@ public void Init(SQLiteStorageOptions storageOptions)
SetRepository = Database.Table<Set>();
StateRepository = Database.Table<State>();
DistributedLockRepository = Database.Table<DistributedLock>();

try
{
Database.Execute($"PRAGMA auto_vacuum = {(int) storageOptions.AutoVacuumSelected};");
}
catch (Exception ex)
{
Logger.Log(LogLevel.Error, () => $"Error set auto vacuum mode. Details: {ex.ToString()}");
}
}

public TableQuery<AggregatedCounter> AggregatedCounterRepository { get; private set; }
Expand Down
12 changes: 12 additions & 0 deletions src/main/Hangfire.Storage.SQLite/SQLiteStorageOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,17 @@ public TimeSpan DistributedLockLifetime
/// Counters interval
/// </summary>
public TimeSpan CountersAggregateInterval { get; set; }

/// <summary>
/// Set AutoVacuum Mode In SQLite
/// </summary>
public AutoVacuum AutoVacuumSelected { get; set; } = AutoVacuum.NONE;

public enum AutoVacuum
{
NONE = 0,
FULL = 1,
INCREMENTAL = 2
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ public override void ExpireJob(string jobId, TimeSpan expireIn)
{
var iJobId = int.Parse(jobId);
var job = _.HangfireJobRepository.FirstOrDefault(x => x.Id == iJobId);
if (job != null)
{
job.ExpireAt = DateTime.UtcNow.Add(expireIn);
var expireAt = DateTime.UtcNow.Add(expireIn);
job.ExpireAt = expireAt;
_.Database.Update(job);
_.Database.Execute($"UPDATE [{DefaultValues.StateTblName}] SET ExpireAt = {expireAt.Ticks} WHERE JobId = {jobId}");
_.Database.Execute($"UPDATE [{DefaultValues.JobParameterTblName}] SET ExpireAt = {expireAt.Ticks} WHERE JobId = {jobId}");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void Ctor_WaitForLock_OnlySingleLockCanBeAcquired()

manualResetEvent.Set();

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

// All the threads should report success.
Interlocked.MemoryBarrier();
Expand Down

0 comments on commit c69d5de

Please sign in to comment.