Skip to content

Commit a602062

Browse files
* Fix bug in GetTTL method
* Switch all applicable ID column types from int to long * Fix index offset issue in methods that look for a range of table entries * Properly implement function to get fetched job ids * Return correct exception during NHibernate session factory generation * Optimize where the schema update is occurring during session factory generation
1 parent 5839df3 commit a602062

25 files changed

+180
-107
lines changed

Hangfire.FluentNHibernate.SampleApplication/Form1.cs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private ProviderTypeEnum ProviderType
5252
get => (ProviderTypeEnum) DataProviderComboBox.SelectedItem;
5353
set
5454
{
55-
ConnectionStringTextBox.Text = LoadConnectionString(value);
55+
ConnectionStringTextBox.Text = LoadProviderSetting(value).ConnectionString;
5656
DataProviderComboBox.SelectedItem = value;
5757
}
5858
}
@@ -78,30 +78,35 @@ protected override void OnClosing(CancelEventArgs e)
7878
base.OnClosing(e);
7979
}
8080

81-
private Dictionary<ProviderTypeEnum, string> GetSettings()
81+
private Dictionary<ProviderTypeEnum, ProviderSetting> GetSettings()
8282
{
83-
var a = Settings.Default.ConnectionStrings;
83+
var a = Settings.Default.ProviderSettings;
8484
try
8585
{
86-
return JsonConvert.DeserializeObject<Dictionary<ProviderTypeEnum, string>>(a) ??
87-
new Dictionary<ProviderTypeEnum, string>
88-
{
89-
{
90-
ProviderTypeEnum.MsSql2012,
91-
"Data Source=.\\sqlexpress;Database=northwind;Trusted_Connection=True;"
92-
}
93-
};
86+
var tmp = JsonConvert.DeserializeObject<Dictionary<ProviderTypeEnum, ProviderSetting>>(a);
87+
if (tmp != null)
88+
{
89+
return tmp;
90+
}
91+
9492
}
95-
catch
93+
catch(Exception ex)
9694
{
97-
return new Dictionary<ProviderTypeEnum, string>();
95+
loggerNew.Error("Error reading settings", ex);
9896
}
97+
return new Dictionary<ProviderTypeEnum, ProviderSetting>
98+
{
99+
{
100+
ProviderTypeEnum.MsSql2012,
101+
new ProviderSetting(){ConnectionString = "Data Source=.\\sqlexpress;Database=northwind;Trusted_Connection=True;"}
102+
}
103+
};
99104
}
100105

101-
private string LoadConnectionString(ProviderTypeEnum persistenceConfigurer)
106+
private ProviderSetting LoadProviderSetting(ProviderTypeEnum persistenceConfigurer)
102107
{
103108
var settings = GetSettings();
104-
return settings.ContainsKey(persistenceConfigurer) ? settings[persistenceConfigurer] : string.Empty;
109+
return settings.ContainsKey(persistenceConfigurer) ? settings[persistenceConfigurer] : new ProviderSetting();
105110
}
106111

107112
private void Form1_Load(object sender, EventArgs e1)
@@ -128,7 +133,7 @@ private void Form1_Load(object sender, EventArgs e1)
128133
private void DataProviderComboBox_SelectedIndexChanged(object sender, EventArgs e)
129134
{
130135
ConnectionStringTextBox.Text =
131-
LoadConnectionString((ProviderTypeEnum) DataProviderComboBox.SelectedItem);
136+
LoadProviderSetting((ProviderTypeEnum) DataProviderComboBox.SelectedItem).ConnectionString;
132137
}
133138

134139
private FluentNHibernateJobStorage storage = null;
@@ -190,8 +195,8 @@ private void StartButton_Click(object sender, EventArgs e)
190195
private void SaveConnectionString(ProviderTypeEnum providerType, string connectionString)
191196
{
192197
var dictionary = GetSettings();
193-
dictionary[providerType] = connectionString;
194-
Settings.Default.ConnectionStrings = JsonConvert.SerializeObject(dictionary);
198+
dictionary[providerType] = new ProviderSetting() {ConnectionString = connectionString};
199+
Settings.Default.ProviderSettings = JsonConvert.SerializeObject(dictionary);
195200
Settings.Default.Save();
196201
}
197202

@@ -223,5 +228,10 @@ private void HQLButton_Click(object sender, EventArgs e)
223228
var f = new HQLForm(this.storage);
224229
f.ShowDialog(this);
225230
}
231+
232+
public class ProviderSetting
233+
{
234+
public string ConnectionString { get; set; }
235+
}
226236
}
227237
}

Hangfire.FluentNHibernate.SampleApplication/Properties/Settings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Hangfire.FluentNHibernateStorage.Tests/ExpirationManagerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ExpirationManagerTests()
2222
private readonly BackgroundProcessContext _context;
2323
private readonly FluentNHibernateStorage.FluentNHibernateJobStorage _storage;
2424

25-
private static int CreateExpirationEntry(SessionWrapper session, DateTime? expireAt)
25+
private static long CreateExpirationEntry(SessionWrapper session, DateTime? expireAt)
2626
{
2727
session.DeleteAll<_AggregatedCounter>();
2828
var a = new _AggregatedCounter {Key = "key", Value = 1, ExpireAt = expireAt};
@@ -31,7 +31,7 @@ private static int CreateExpirationEntry(SessionWrapper session, DateTime? expir
3131
return a.Id;
3232
}
3333

34-
private static bool IsEntryExpired(SessionWrapper session, int entryId)
34+
private static bool IsEntryExpired(SessionWrapper session, long entryId)
3535
{
3636
var count = session.Query<_AggregatedCounter>().Count(i => i.Id == entryId);
3737

Hangfire.FluentNHibernateStorage/CountersAggregator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace Hangfire.FluentNHibernateStorage
99
{
10+
#pragma warning disable 618
1011
public class CountersAggregator : IBackgroundProcess, IServerComponent
1112
{
13+
#pragma warning restore 618
1214
private const int NumberOfRecordsInSinglePass = 1000;
1315
private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();
1416
private static readonly TimeSpan DelayBetweenPasses = TimeSpan.FromMilliseconds(500);
@@ -77,7 +79,7 @@ public void Execute(CancellationToken cancellationToken)
7779
;
7880
}
7981
removedCount =
80-
session.DeleteByInt32Id<_Counter>(counters.Select(counter => counter.Id).ToArray());
82+
session.DeleteByInt64Id<_Counter>(counters.Select(counter => counter.Id).ToArray());
8183

8284
transaction.Commit();
8385
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Hangfire.FluentNHibernateStorage.Entities
22
{
3-
public abstract class EntityBase0 : IInt32Id
3+
public abstract class EntityBase0 : IInt64Id
44
{
5-
public virtual int Id { get; set; }
5+
public virtual long Id { get; set; }
66
}
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Hangfire.FluentNHibernateStorage.Entities
22
{
3-
internal interface IExpirableWithId : IExpirable, IInt32Id
3+
internal interface IExpirableWithId : IExpirable, IInt64Id
44
{
55
}
66
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Hangfire.FluentNHibernateStorage.Entities
22
{
3-
public interface IInt32Id
3+
public interface IInt64Id
44
{
5-
int Id { get; set; }
5+
long Id { get; set; }
66
}
77
}

Hangfire.FluentNHibernateStorage/Entities/_Job.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public _Job()
2626
public virtual DateTime? LastStateChangedAt { get; set; }
2727
public virtual string StateData { get; set; }
2828

29-
public virtual int Id { get; set; }
29+
public virtual long Id { get; set; }
3030
public virtual DateTime? ExpireAt { get; set; }
3131
}
3232
}

Hangfire.FluentNHibernateStorage/ExpirationManager.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
namespace Hangfire.FluentNHibernateStorage
1010
{
11+
#pragma warning disable 618
1112
public class ExpirationManager : IBackgroundProcess, IServerComponent
1213
{
14+
#pragma warning restore 618
1315
private const string DistributedLockKey = "expirationmanager";
1416
private const int NumberOfRecordsInSinglePass = 1000;
1517
private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();
@@ -42,13 +44,13 @@ public void Execute(BackgroundProcessContext context)
4244
private long DeleteExpirableWithId<T>(SessionWrapper session, DateTime baseDate) where T : IExpirableWithId
4345

4446
{
45-
List<int> ids;
47+
List<long> ids;
4648
ids = session.Query<T>()
4749
.Where(i => i.ExpireAt < baseDate)
4850
.Take(NumberOfRecordsInSinglePass)
4951
.Select(i => i.Id)
5052
.ToList();
51-
return session.DeleteByInt32Id<T>(ids);
53+
return session.DeleteByInt64Id<T>(ids);
5254
}
5355

5456

@@ -108,7 +110,7 @@ public void Execute(CancellationToken cancellationToken)
108110
.Take(NumberOfRecordsInSinglePass)
109111
.Select(i => i.Id)
110112
.ToList();
111-
return session.DeleteByInt32Id<_JobState>(idList);
113+
return session.DeleteByInt64Id<_JobState>(idList);
112114
});
113115
BatchDelete<_JobQueue>(cancellationToken, (session, baseDate2) =>
114116
{
@@ -117,7 +119,7 @@ public void Execute(CancellationToken cancellationToken)
117119
.Take(NumberOfRecordsInSinglePass)
118120
.Select(i => i.Id)
119121
.ToList();
120-
return session.DeleteByInt32Id<_JobState>(idList);
122+
return session.DeleteByInt64Id<_JobState>(idList);
121123
});
122124
BatchDelete<_JobParameter>(cancellationToken, (session, baseDate2) =>
123125
{
@@ -126,7 +128,7 @@ public void Execute(CancellationToken cancellationToken)
126128
.Take(NumberOfRecordsInSinglePass)
127129
.Select(i => i.Id)
128130
.ToList();
129-
return session.DeleteByInt32Id<_JobParameter>(idList);
131+
return session.DeleteByInt64Id<_JobParameter>(idList);
130132
});
131133
BatchDelete<_DistributedLock>(cancellationToken, (session, baseDate2) =>
132134
{
@@ -135,7 +137,7 @@ public void Execute(CancellationToken cancellationToken)
135137
.Take(NumberOfRecordsInSinglePass)
136138
.Select(i => i.Id)
137139
.ToList();
138-
return session.DeleteByInt32Id<_DistributedLock>(idList);
140+
return session.DeleteByInt64Id<_DistributedLock>(idList);
139141
});
140142
BatchDelete<_AggregatedCounter>(cancellationToken, DeleteExpirableWithId<_AggregatedCounter>);
141143
BatchDelete<_Job>(cancellationToken, DeleteExpirableWithId<_Job>);

0 commit comments

Comments
 (0)