Skip to content

Commit

Permalink
expression fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mobydi committed Oct 9, 2015
1 parent 586897e commit 70e6162
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Hangfire.SQLite/SQLiteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public override string GetJobParameter(string jobId, string name)
if (name == null) throw new ArgumentNullException("name");

return _connection.Query<string>(
@"select Value from [HangFire.JobParameter] where JobId = @jobId and Name = @name",
@"select Value from [HangFire.JobParameter] where JobId = @jobId and Name = @name limit 1",
new { jobId = jobId, name = name })
.SingleOrDefault();
}
Expand Down
18 changes: 9 additions & 9 deletions Hangfire.Sqlite/SqliteMonitoringApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,36 +329,36 @@ public StatisticsDto GetStatistics()
having StateName is not null;
select count(Id) from [HangFire.Server];
select sum(s.[Value]) from (
select sum([Value]) as [Value] from [HangFire.Counter] where [Key] = N'stats:succeeded'
select sum([Value]) as [Value] from [HangFire.Counter] where [Key] = 'stats:succeeded'
union all
select [Value] from [HangFire.AggregatedCounter] where [Key] = N'stats:succeeded'
select [Value] from [HangFire.AggregatedCounter] where [Key] = 'stats:succeeded'
) as s;
select sum(s.[Value]) from (
select sum([Value]) as [Value] from [HangFire.Counter] where [Key] = N'stats:deleted'
select sum([Value]) as [Value] from [HangFire.Counter] where [Key] = 'stats:deleted'
union all
select [Value] from [HangFire.AggregatedCounter] where [Key] = N'stats:deleted'
select [Value] from [HangFire.AggregatedCounter] where [Key] = 'stats:deleted'
) as s;
select count(*) from [HangFire.Set] where [Key] = N'recurring-jobs';
select count(*) from [HangFire.Set] where [Key] = 'recurring-jobs';
";
var stats = new StatisticsDto();
using (var multi = connection.QueryMultiple(sql))
{
var countByStates = multi.Read().ToDictionary(x => x.State, x => x.Count);
Func<string, int> getCountIfExists = name => countByStates.ContainsKey(name) ? countByStates[name] : 0;
Func<string, long> getCountIfExists = name => countByStates.ContainsKey(name) ? countByStates[name] : 0;
stats.Enqueued = getCountIfExists(EnqueuedState.StateName);
stats.Failed = getCountIfExists(FailedState.StateName);
stats.Processing = getCountIfExists(ProcessingState.StateName);
stats.Scheduled = getCountIfExists(ScheduledState.StateName);
stats.Servers = multi.Read<int>().Single();
stats.Servers = multi.Read<long?>().SingleOrDefault() ?? 0;
stats.Succeeded = multi.Read<long?>().SingleOrDefault() ?? 0;
stats.Deleted = multi.Read<long?>().SingleOrDefault() ?? 0;
stats.Recurring = multi.Read<int>().Single();
stats.Recurring = multi.Read<long?>().SingleOrDefault() ?? 0;
}
stats.Queues = _queueProviders
Expand Down Expand Up @@ -407,7 +407,7 @@ union all
IDictionary<string, DateTime> keyMaps)
{
const string sqlQuery = @"
select [Key], [Value] as Count from [HangFire].[AggregatedCounter]
select [Key], [Value] as Count from [HangFire.AggregatedCounter]
where [Key] in @keys";

var valuesMap = connection.Query(
Expand Down
23 changes: 9 additions & 14 deletions Hangfire.Sqlite/SqliteWriteOnlyTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public override void Commit()
{
//_connection.EnlistTransaction(Transaction.Current); TODO

if (_lockedResources.Count > 0)
{
_connection.Execute(
"set nocount on;" +
"exec sp_getapplock @Resource=@resource, @LockMode=N'Exclusive'",
_lockedResources.Select(x => new { resource = x }));
}
//if (_lockedResources.Count > 0)
//{
// _connection.Execute(
// "set nocount on;" +
// "exec sp_getapplock @Resource=@resource, @LockMode=N'Exclusive'",
// _lockedResources.Select(x => new { resource = x }));
//}

foreach (var command in _commandQueue)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public override void SetJobState(string jobId, IState state)
});
var stateId = x.ExecuteScalar<long>(selectStateSql);
System.IO.File.AppendAllText(@"d:\log.txt", stateId + " " + state.Name + "\n");
x.Execute(setStateSql,
new
{
Expand Down Expand Up @@ -184,12 +184,7 @@ public override void AddToSet(string key, string value)

public override void AddToSet(string key, string value, double score)
{
const string addSql = @"
;merge [HangFire.Set] with (holdlock) as Target
using (VALUES (@key, @value, @score)) as Source ([Key], Value, Score)
on Target.[Key] = Source.[Key] and Target.Value = Source.Value
when matched then update set Score = Source.Score
when not matched then insert ([Key], Value, Score) values (Source.[Key], Source.Value, Source.Score);";
const string addSql = @"insert or replace into [HangFire.Set] ([Key], [Value], [Score]) values (@key, @value, @score)";

AcquireSetLock();
QueueCommand(x => x.Execute(
Expand Down

0 comments on commit 70e6162

Please sign in to comment.