Browse Source

fix postgre sql bug.

master
Savorboard 7 years ago
parent
commit
a65fe37dcc
3 changed files with 16 additions and 17 deletions
  1. +1
    -1
      src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs
  2. +13
    -14
      src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs
  3. +2
    -2
      src/DotNetCore.CAP/IConsumerHandler.Default.cs

+ 1
- 1
src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs View File

@@ -34,7 +34,7 @@ namespace DotNetCore.CAP
using (var scope = x.CreateScope()) using (var scope = x.CreateScope())
{ {
var provider = scope.ServiceProvider; var provider = scope.ServiceProvider;
var dbContext = (DbContext) provider.GetService(postgreSqlOptions.DbContextType);
var dbContext = (DbContext)provider.GetService(postgreSqlOptions.DbContextType);
postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
return postgreSqlOptions; return postgreSqlOptions;
} }


+ 13
- 14
src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs View File

@@ -24,12 +24,12 @@ namespace DotNetCore.CAP.PostgreSql
public StatisticsDto GetStatistics() public StatisticsDto GetStatistics()
{ {
var sql = string.Format(@" var sql = string.Format(@"
select count(Id) from ""{0}"".""published"" where ""StatusName"" = N'Succeeded';
select count(Id) from ""{0}"".""received"" where ""StatusName"" = N'Succeeded';
select count(Id) from ""{0}"".""published"" where ""StatusName"" = N'Failed';
select count(Id) from ""{0}"".""received"" where ""StatusName"" = N'Failed';
select count(Id) from ""{0}"".""published"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued');
select count(Id) from ""{0}"".""received"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued');",
select count(""Id"") from ""{0}"".""published"" where ""StatusName"" = N'Succeeded';
select count(""Id"") from ""{0}"".""received"" where ""StatusName"" = N'Succeeded';
select count(""Id"") from ""{0}"".""published"" where ""StatusName"" = N'Failed';
select count(""Id"") from ""{0}"".""received"" where ""StatusName"" = N'Failed';
select count(""Id"") from ""{0}"".""published"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued');
select count(""Id"") from ""{0}"".""received"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued');",
_options.Schema); _options.Schema);


var statistics = UseConnection(connection => var statistics = UseConnection(connection =>
@@ -130,10 +130,10 @@ select count(Id) from ""{0}"".""received"" where ""StatusName"" in (N'Processin
private int GetNumberOfMessage(IDbConnection connection, string tableName, string statusName) private int GetNumberOfMessage(IDbConnection connection, string tableName, string statusName)
{ {
var sqlQuery = statusName == StatusName.Processing var sqlQuery = statusName == StatusName.Processing
? $"select count(Id) from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" in (N'Processing',N'Scheduled',N'Enqueued')"
: $"select count(Id) from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" = @state";
? $"select count(\"Id\") from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" in (N'Processing',N'Scheduled',N'Enqueued')"
: $"select count(\"Id\") from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" = @state";


var count = connection.ExecuteScalar<int>(sqlQuery, new {state = statusName});
var count = connection.ExecuteScalar<int>(sqlQuery, new { state = statusName });
return count; return count;
} }


@@ -174,12 +174,11 @@ with aggr as (
where ""StatusName"" = N'Processing' where ""StatusName"" = N'Processing'
group by to_char(""Added"", 'yyyy-MM-dd-HH') group by to_char(""Added"", 'yyyy-MM-dd-HH')
) )
select ""Key"",""Count"" from aggr where ""Key"" in @keys;";
select ""Key"",""Count"" from aggr where ""Key""=Any(@keys);";


var valuesMap = connection.Query(
sqlQuery,
new {keys = keyMaps.Keys, statusName})
.ToDictionary(x => (string) x.Key, x => (int) x.Count);
var valuesMap = connection.Query(sqlQuery,new { keys = keyMaps.Keys.ToList(), statusName })
.ToList()
.ToDictionary(x => (string)x.Key, x => (int)x.Count);


foreach (var key in keyMaps.Keys) foreach (var key in keyMaps.Keys)
if (!valuesMap.ContainsKey(key)) valuesMap.Add(key, 0); if (!valuesMap.ContainsKey(key)) valuesMap.Add(key, 0);


+ 2
- 2
src/DotNetCore.CAP/IConsumerHandler.Default.cs View File

@@ -40,9 +40,9 @@ namespace DotNetCore.CAP


public void Start() public void Start()
{ {
var groupingMatchs = _selector.GetCandidatesMethodsOfGroupNameGrouped();
var groupingMatches = _selector.GetCandidatesMethodsOfGroupNameGrouped();


foreach (var matchGroup in groupingMatchs)
foreach (var matchGroup in groupingMatches)
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
using (var client = _consumerClientFactory.Create(matchGroup.Key)) using (var client = _consumerClientFactory.Create(matchGroup.Key))


Loading…
Cancel
Save