Skip to content

Commit b5648f5

Browse files
authored
Merge pull request #8 from raisedapp/develop
Version 0.0.2
2 parents 8afd3f8 + 5e02ec6 commit b5648f5

14 files changed

+1165
-32
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@
77
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
88
</PropertyGroup>
99
<PropertyGroup>
10-
<Version>0.0.1</Version>
11-
<Authors>felixclase</Authors>
12-
<Company>felixclase</Company>
10+
<Version>0.0.2</Version>
11+
<Authors>RaisedApp</Authors>
12+
<Company>RaisedApp</Company>
1313
<Copyright>Copyright © 2019 - Present</Copyright>
1414
<PackageLicenseFile>LICENSE</PackageLicenseFile>
15-
<PackageProjectUrl>https://github.com/felixclase/Hangfire.Storage.SQLite</PackageProjectUrl>
16-
<RepositoryUrl>https://github.com/felixclase/Hangfire.Storage.SQLite</RepositoryUrl>
15+
<PackageProjectUrl>https://github.com/raisedapp/Hangfire.Storage.SQLite</PackageProjectUrl>
16+
<RepositoryUrl>https://github.com/raisedapp/Hangfire.Storage.SQLite</RepositoryUrl>
1717
<RepositoryType>git</RepositoryType>
18-
<PackageTags>hangfire hangfire-storage sqlite</PackageTags>
18+
<PackageTags>Hangfire Hangfire-Storage Hangfire-Extension SQLite</PackageTags>
1919
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
20+
<title>Hangfire Storage SQLite</title>
2021
<Description>An Alternative SQLite Storage for Hangfire</Description>
22+
<PackageReleaseNotes>
23+
0.0.1
24+
- Added the missing methods of the SQLiteWriteOnlyTransaction class
25+
</PackageReleaseNotes>
2126
</PropertyGroup>
2227
<ItemGroup>
2328
<None Include="..\..\..\LICENSE">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Hangfire.Storage.SQLite
1010
/// <summary>
1111
/// Represents distibuted lock implementation for SQLite
1212
/// </summary>
13-
internal class SQLiteDistributedLock : IDisposable
13+
public class SQLiteDistributedLock : IDisposable
1414
{
1515
// EventWaitHandle is not supported on UNIX systems
1616
// https://github.com/dotnet/coreclr/pull/1387

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

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,134 @@ public override void ExpireHash(string key, TimeSpan expireIn)
394394
}
395395
});
396396
}
397+
398+
/// <summary>
399+
///
400+
/// </summary>
401+
/// <param name="key"></param>
402+
/// <param name="expireIn"></param>
403+
/// <exception cref="ArgumentNullException"></exception>
404+
public override void ExpireSet(string key, TimeSpan expireIn)
405+
{
406+
if (key == null) throw new ArgumentNullException(nameof(key));
407+
408+
QueueCommand(x =>
409+
{
410+
var states = x.SetRepository.Where(_ => _.Key == key).ToList();
411+
foreach(var state in states)
412+
{
413+
state.ExpireAt = DateTime.UtcNow.Add(expireIn);
414+
x.Database.Update(state);
415+
}
416+
});
417+
}
418+
419+
/// <summary>
420+
///
421+
/// </summary>
422+
/// <param name="key"></param>
423+
/// <exception cref="ArgumentNullException"></exception>
424+
public override void PersistSet(string key)
425+
{
426+
if (key == null) throw new ArgumentNullException(nameof(key));
427+
QueueCommand(x =>
428+
{
429+
var states = x.SetRepository.Where(_ => _.Key == key).ToList();
430+
foreach(var state in states)
431+
{
432+
state.ExpireAt = DateTime.MinValue;
433+
x.Database.Update(state);
434+
}
435+
436+
});
437+
}
438+
439+
/// <summary>
440+
///
441+
/// </summary>
442+
/// <param name="key"></param>
443+
/// <exception cref="ArgumentNullException"></exception>
444+
public override void PersistList(string key)
445+
{
446+
if (key == null) throw new ArgumentNullException(nameof(key));
447+
QueueCommand(x =>
448+
{
449+
var states = x.HangfireListRepository.Where(_ => _.Key == key).ToList();
450+
foreach(var state in states)
451+
{
452+
state.ExpireAt = DateTime.MinValue;
453+
x.Database.Update(state);
454+
}
455+
});
456+
}
457+
458+
/// <summary>
459+
///
460+
/// </summary>
461+
/// <param name="key"></param>
462+
/// <exception cref="ArgumentNullException"></exception>
463+
public override void PersistHash(string key)
464+
{
465+
if (key == null) throw new ArgumentNullException(nameof(key));
466+
QueueCommand(x =>
467+
{
468+
var states = x.HashRepository.Where(_ => _.Key == key).ToList();
469+
foreach(var state in states)
470+
{
471+
state.ExpireAt = DateTime.MinValue;
472+
x.Database.Update(state);
473+
}
474+
});
475+
}
476+
477+
/// <summary>
478+
///
479+
/// </summary>
480+
/// <param name="key"></param>
481+
/// <param name="items"></param>
482+
/// <exception cref="ArgumentNullException"></exception>
483+
public override void AddRangeToSet(string key, IList<string> items)
484+
{
485+
if (key == null) throw new ArgumentNullException(nameof(key));
486+
if (items == null) throw new ArgumentNullException(nameof(items));
487+
488+
foreach (var item in items)
489+
{
490+
QueueCommand(x =>
491+
{
492+
var state = new Set
493+
{
494+
Key = key,
495+
Value = item,
496+
ExpireAt = DateTime.MinValue,
497+
Score = 0.0m
498+
};
499+
500+
var oldSet = x.SetRepository.FirstOrDefault(_ => _.Key == key && _.Value == item);
501+
502+
if (oldSet == null)
503+
{
504+
x.Database.Insert(state);
505+
}
506+
else
507+
{
508+
state.Id = oldSet.Id;
509+
x.Database.Update(state);
510+
}
511+
});
512+
}
513+
}
514+
515+
/// <summary>
516+
///
517+
/// </summary>
518+
/// <param name="key"></param>
519+
/// <exception cref="ArgumentNullException"></exception>
520+
public override void RemoveSet(string key)
521+
{
522+
if (key == null) throw new ArgumentNullException(nameof(key));
523+
QueueCommand(x => x.SetRepository.Delete(_ => _.Key == key));
524+
}
397525

398526
/// <summary>
399527
///

src/samples/ConsoleSample/ConsoleSample.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp2.2</TargetFramework>
66
<IsPackable>false</IsPackable>
7-
<Authors>felixclase</Authors>
7+
<Authors>RaisedApp</Authors>
8+
<Company>RaisedApp</Company>
89
<Copyright>Copyright © 2019 - Present</Copyright>
910
<PackageLicenseFile>LICENSE</PackageLicenseFile>
10-
<PackageProjectUrl>https://github.com/felixclase/Hangfire.Storage.SQLite</PackageProjectUrl>
11-
<RepositoryUrl>https://github.com/felixclase/Hangfire.Storage.SQLite</RepositoryUrl>
12-
<RepositoryType>git</RepositoryType>
11+
<PackageProjectUrl>https://github.com/raisedapp/Hangfire.Storage.SQLite</PackageProjectUrl>
12+
<RepositoryUrl>https://github.com/raisedapp/Hangfire.Storage.SQLite</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
1314
</PropertyGroup>
1415

1516
<ItemGroup>

src/samples/WebSample/WebSample.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<IsPackable>false</IsPackable>
7-
<Authors>felixclase</Authors>
7+
<Authors>RaisedApp</Authors>
8+
<Company>RaisedApp</Company>
89
<Copyright>Copyright © 2019 - Present</Copyright>
910
<PackageLicenseFile>LICENSE</PackageLicenseFile>
10-
<PackageProjectUrl>https://github.com/felixclase/Hangfire.Storage.SQLite</PackageProjectUrl>
11-
<RepositoryUrl>https://github.com/felixclase/Hangfire.Storage.SQLite</RepositoryUrl>
12-
<RepositoryType>git</RepositoryType>
11+
<PackageProjectUrl>https://github.com/raisedapp/Hangfire.Storage.SQLite</PackageProjectUrl>
12+
<RepositoryUrl>https://github.com/raisedapp/Hangfire.Storage.SQLite</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
1314
</PropertyGroup>
1415

1516
<ItemGroup>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Threading;
3+
using Hangfire.Storage.SQLite.Entities;
4+
using Hangfire.Storage.SQLite.Test.Utils;
5+
using SQLite;
6+
using Xunit;
7+
8+
namespace Hangfire.Storage.SQLite.Test
9+
{
10+
[Collection("Database")]
11+
public class CountersAggregatorFacts
12+
{
13+
[Fact, CleanDatabase]
14+
public void CountersAggregatorExecutesProperly()
15+
{
16+
var storage = ConnectionUtils.CreateStorage();
17+
using (var connection = (HangfireSQLiteConnection)storage.GetConnection())
18+
{
19+
// Arrange
20+
connection.DbContext.Database.Insert(new Counter
21+
{
22+
Id = Guid.NewGuid().ToString(),
23+
Key = "key",
24+
Value = 1L,
25+
ExpireAt = DateTime.UtcNow.AddHours(1)
26+
});
27+
28+
var aggregator = new CountersAggregator(storage, TimeSpan.Zero);
29+
var cts = new CancellationTokenSource();
30+
cts.Cancel();
31+
32+
// Act
33+
aggregator.Execute(cts.Token);
34+
35+
// Assert
36+
Assert.Equal(1, connection.DbContext.AggregatedCounterRepository.Count());
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)