Skip to content

Commit 8afd3f8

Browse files
authored
Merge pull request #6 from raisedapp/develop
First beta!
2 parents 0236ede + 9c203a8 commit 8afd3f8

File tree

15 files changed

+111
-109
lines changed

15 files changed

+111
-109
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Hangfire.Storage.SQLite
22
[![NuGet](https://buildstats.info/nuget/Hangfire.Storage.SQLite)](https://www.nuget.org/packages/Hangfire.Storage.SQLite)
3-
[![Actions Status](https://github.com/felixclase/Hangfire.Storage.SQLite/workflows/CI-HS-SQLITE/badge.svg)](https://github.com/felixclase/Hangfire.Storage.SQLite/actions)
3+
[![Actions Status](https://github.com/raisedapp/Hangfire.Storage.SQLite/workflows/CI-HS-SQLITE/badge.svg)](https://github.com/raisedapp/Hangfire.Storage.SQLite/actions)
44
[![Official Site](https://img.shields.io/badge/site-hangfire.io-blue.svg)](http://hangfire.io)
55
[![License MIT](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
66

@@ -13,8 +13,8 @@ This project was created by abandonment **Hangfire.SQLite** storage (https://git
1313
## Build Status
1414
`Platform` | `Master` | `Develop`
1515
--- | --- | ---
16-
**Windows** | [![Build Status](https://circleci.com/gh/felixclase/Hangfire.Storage.SQLite/tree/master.svg?style=svg)](https://circleci.com/gh/felixclase/Hangfire.Storage.SQLite/tree/master) | [![Build Status](https://circleci.com/gh/felixclase/Hangfire.Storage.SQLite/tree/develop.svg?style=svg)](https://circleci.com/gh/felixclase/Hangfire.Storage.SQLite/tree/develop)
17-
**Linux / Mac OS** | [![Build Status](https://travis-ci.org/felixclase/Hangfire.Storage.SQLite.svg?branch=master)](https://travis-ci.org/felixclase/Hangfire.Storage.SQLite/) | [![Build Status](https://travis-ci.org/felixclase/Hangfire.Storage.SQLite.svg?branch=develop)](https://travis-ci.org/felixclase/Hangfire.Storage.SQLite/)
16+
**Windows** | [![Build Status](https://circleci.com/gh/raisedapp/Hangfire.Storage.SQLite/tree/master.svg?style=svg)](https://circleci.com/gh/raisedapp/Hangfire.Storage.SQLite/tree/master) | [![Build Status](https://circleci.com/gh/raisedapp/Hangfire.Storage.SQLite/tree/develop.svg?style=svg)](https://circleci.com/gh/raisedapp/Hangfire.Storage.SQLite/tree/develop)
17+
**Linux / Mac OS** | [![Build Status](https://travis-ci.org/raisedapp/Hangfire.Storage.SQLite.svg?branch=master)](https://travis-ci.org/raisedapp/Hangfire.Storage.SQLite/) | [![Build Status](https://travis-ci.org/raisedapp/Hangfire.Storage.SQLite.svg?branch=develop)](https://travis-ci.org/raisedapp/Hangfire.Storage.SQLite/)
1818

1919
## Installation
2020

@@ -50,4 +50,4 @@ If this project help you reduce time to develop, you can give me a cup of coffee
5050
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=RMLQM296TCM38&item_name=For+the+development+of+Hangfire.Storage.SQLite&currency_code=USD&source=url)
5151

5252
## License
53-
This project is under MIT license. You can obtain the license copy [here](https://github.com/felixclase/Hangfire.Storage.SQLite/blob/develop/LICENSE).
53+
This project is under MIT license. You can obtain the license copy [here](https://github.com/raisedapp/Hangfire.Storage.SQLite/blob/develop/LICENSE).

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,17 @@ namespace Hangfire.Storage.SQLite.Entities
88
[Table("List")]
99
public class HangfireList
1010
{
11-
private string _listPK = string.Empty;
12-
13-
[PrimaryKey]
14-
public string ListPK {
15-
get => Id + "_" + Key;
16-
set => _listPK = value;
17-
}
18-
19-
//[AutoIncrement]
20-
[Indexed(Name = "IX_List_Id", Order = 1, Unique = false)]
11+
[PrimaryKey, AutoIncrement]
2112
public int Id { get; set; }
2213

2314
[MaxLength(DefaultValues.MaxLengthKeyColumn)]
24-
[Indexed(Name = "IX_List_Key", Order = 2, Unique = false)]
15+
[Indexed(Name = "IX_List_Key", Order = 1, Unique = false)]
2516
public string Key { get; set; }
2617

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

30-
[Indexed(Name = "IX_List_ExpireAt", Order = 3, Unique = false)]
21+
[Indexed(Name = "IX_List_ExpireAt", Order = 2, Unique = false)]
3122
public DateTime ExpireAt { get; set; }
3223
}
3324
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ namespace Hangfire.Storage.SQLite.Entities
77
{
88
public class Hash
99
{
10-
private string _hashPK = string.Empty;
11-
12-
[PrimaryKey]
13-
public string HashPK {
14-
get => Key + "_" + Field;
15-
set => _hashPK = value;
16-
}
10+
[PrimaryKey, AutoIncrement]
11+
public int Id { get; set; }
1712

1813
[MaxLength(DefaultValues.MaxLengthKeyColumn)]
1914
[Indexed(Name = "IX_Hash_Key", Order = 1, Unique = false)]

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ namespace Hangfire.Storage.SQLite.Entities
77
{
88
public class JobParameter
99
{
10-
private string _jobParameterPK = string.Empty;
11-
12-
[PrimaryKey]
13-
public string JobParameterPK {
14-
get => JobId + "_" + Name;
15-
set => _jobParameterPK = value;
16-
}
10+
[PrimaryKey, AutoIncrement]
11+
public int Id { get; set; }
1712

1813
[Indexed(Name = "IX_JobParameter_JobId", Order = 1, Unique = false)]
1914
public int JobId { get; set; }

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@ namespace Hangfire.Storage.SQLite.Entities
77
{
88
public class JobQueue
99
{
10-
private string _jobQueuePK = string.Empty;
11-
[PrimaryKey]
12-
public string JobQueuePK {
13-
get => Id + "_" + Queue;
14-
set => _jobQueuePK = value;
15-
}
16-
17-
//[AutoIncrement]
18-
[Indexed(Name = "IX_JobQueue_Id", Order = 1, Unique = false)]
10+
[PrimaryKey, AutoIncrement]
1911
public int Id { get; set; }
2012

2113
public int JobId { get; set; }
2214

2315
[MaxLength(DefaultValues.MaxLengthQueueColumn)]
24-
[Indexed(Name = "IX_JobQueue_Queue", Order = 2, Unique = false)]
16+
[Indexed(Name = "IX_JobQueue_Queue", Order = 1, Unique = false)]
2517
public string Queue { get; set; }
2618

27-
[Indexed(Name = "IX_JobQueue_FetchedAt", Order = 3, Unique = false)]
19+
[Indexed(Name = "IX_JobQueue_FetchedAt", Order = 2, Unique = false)]
2820
public DateTime FetchedAt { get; set; }
2921
}
3022
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ namespace Hangfire.Storage.SQLite.Entities
77
{
88
public class Set
99
{
10-
private string _setPK = string.Empty;
11-
12-
[PrimaryKey]
13-
public string SetPK { get { return Key + "_" + Value; } set { _setPK = value; } }
10+
[PrimaryKey, AutoIncrement]
11+
public int Id { get; set; }
1412

1513
[MaxLength(DefaultValues.MaxLengthKeyColumn)]
1614
[Indexed(Name = "IX_Set_Key", Order = 1, Unique = false)]

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@ namespace Hangfire.Storage.SQLite.Entities
77
{
88
public class State
99
{
10-
private string _statePK = string.Empty;
11-
12-
[PrimaryKey]
13-
public string StatePK {
14-
get => Id + "_" + JobId;
15-
set => _statePK = value;
16-
}
17-
18-
//[AutoIncrement]
19-
[Indexed(Name = "IX_State_Id", Order = 1, Unique = false)]
10+
[PrimaryKey, AutoIncrement]
2011
public int Id { get; set; }
2112

22-
[Indexed(Name = "IX_State_JobId", Order = 2, Unique = false)]
13+
[Indexed(Name = "IX_State_JobId", Order = 1, Unique = false)]
2314
public int JobId { get; set; }
2415

2516
[MaxLength(DefaultValues.MaxLengthStateNameColumn)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public override Dictionary<string, string> GetAllEntriesFromHash(string key)
156156
var result = DbContext
157157
.HashRepository
158158
.Where(_ => _.Key == key)
159-
.AsEnumerable()
160159
.Select(_ => new { _.Field, _.Value })
160+
.ToList()
161161
.ToDictionary(x => x.Field, x => x.Value);
162162

163163
return result.Count != 0 ? result : null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Hangfire.Storage.SQLite
77
/// <summary>
88
///
99
/// </summary>
10-
public class SQLiteFetchedJob
10+
public class SQLiteFetchedJob : IFetchedJob
1111
{
1212
private readonly HangfireDbContext _dbContext;
1313
private readonly int _id;
Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Hangfire.Storage.SQLite.Entities;
2+
using System;
23
using System.Collections.Generic;
34
using System.Text;
45
using System.Threading;
@@ -30,7 +31,6 @@ public SQLiteJobQueue(HangfireDbContext connection, SQLiteStorageOptions storage
3031
/// <returns></returns>
3132
public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
3233
{
33-
/*
3434
if (queues == null)
3535
{
3636
throw new ArgumentNullException(nameof(queues));
@@ -41,51 +41,35 @@ public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
4141
throw new ArgumentException("Queue array must be non-empty.", nameof(queues));
4242
}
4343

44-
var fetchConditions = new[]
45-
{
46-
Query.EQ("FetchedAt", null),
47-
Query.LT("FetchedAt", DateTime.UtcNow.AddSeconds(_storageOptions.InvisibilityTimeout.Negate().TotalSeconds))
48-
};
49-
var fetchConditionsIndex = 0;
50-
5144
JobQueue fetchedJob = null;
5245
while (fetchedJob == null)
5346
{
5447
cancellationToken.ThrowIfCancellationRequested();
5548

56-
var fetchCondition = fetchConditions[fetchConditionsIndex];
57-
5849
foreach (var queue in queues)
5950
{
6051
var lockQueue = string.Intern($"f13333e1-a0c8-48c8-bf8c-788e89030329_{queue}");
6152
lock (lockQueue)
6253
{
63-
fetchedJob = _connection.JobQueue.FindOne(Query.And(fetchCondition, Query.EQ("Queue", queue)));
54+
fetchedJob = _dbContext.JobQueueRepository.FirstOrDefault(_ => _.Queue == queue &&
55+
(_.FetchedAt == DateTime.MinValue));
6456

6557
if (fetchedJob != null)
6658
{
6759
fetchedJob.FetchedAt = DateTime.UtcNow;
68-
_connection.JobQueue.Update(fetchedJob);
60+
_dbContext.Database.Update(fetchedJob);
61+
6962
break;
7063
}
7164
}
7265
}
7366

74-
if (fetchedJob == null && fetchConditionsIndex == fetchConditions.Length - 1)
75-
{
76-
// ...and we are out of fetch conditions as well.
77-
// Wait for a while before polling again.
78-
cancellationToken.WaitHandle.WaitOne(_storageOptions.QueuePollInterval);
79-
cancellationToken.ThrowIfCancellationRequested();
80-
}
81-
82-
// Move on to next fetch condition
83-
fetchConditionsIndex = (fetchConditionsIndex + 1) % fetchConditions.Length;
67+
// Wait for a while before polling again.
68+
cancellationToken.WaitHandle.WaitOne(_storageOptions.QueuePollInterval);
69+
cancellationToken.ThrowIfCancellationRequested();
8470
}
8571

86-
return new LiteDbFetchedJob(_connection, fetchedJob.Id, fetchedJob.JobId, fetchedJob.Queue);
87-
*/
88-
return null;
72+
return new SQLiteFetchedJob(_dbContext, fetchedJob.Id, fetchedJob.JobId, fetchedJob.Queue);
8973
}
9074

9175
/// <summary>
@@ -95,13 +79,11 @@ public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
9579
/// <param name="jobId"></param>
9680
public void Enqueue(string queue, string jobId)
9781
{
98-
/*
99-
_connection.JobQueue.Insert(new JobQueue
82+
_dbContext.Database.Insert(new JobQueue
10083
{
10184
JobId = int.Parse(jobId),
10285
Queue = queue
10386
});
104-
*/
10587
}
10688
}
10789
}

0 commit comments

Comments
 (0)