Sfoglia il codice sorgente

fix postgre sql bug.

master
Savorboard 7 anni fa
parent
commit
a65fe37dcc
3 ha cambiato i file con 16 aggiunte e 17 eliminazioni
  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 Vedi File

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


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

@@ -24,12 +24,12 @@ namespace DotNetCore.CAP.PostgreSql
public StatisticsDto GetStatistics()
{
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);

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)
{
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;
}

@@ -174,12 +174,11 @@ with aggr as (
where ""StatusName"" = N'Processing'
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)
if (!valuesMap.ContainsKey(key)) valuesMap.Add(key, 0);


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

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

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

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


Caricamento…
Annulla
Salva