Selaa lähdekoodia

fix sqlserver dashboard query bug (#600)

* fix bug

* fix bug

Co-authored-by: wandone\xlw <123456>
master
xiangxiren 4 vuotta sitten
committed by GitHub
vanhempi
commit
338ba4c201
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 muutettua tiedostoa jossa 32 lisäystä ja 53 poistoa
  1. +1
    -1
      src/DotNetCore.CAP.Dashboard/DashboardRoutes.cs
  2. +10
    -16
      src/DotNetCore.CAP.MySql/IDataStorage.MySql.cs
  3. +10
    -17
      src/DotNetCore.CAP.PostgreSql/IDataStorage.PostgreSql.cs
  4. +10
    -18
      src/DotNetCore.CAP.SqlServer/IDataStorage.SqlServer.cs
  5. +1
    -1
      src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs

+ 1
- 1
src/DotNetCore.CAP.Dashboard/DashboardRoutes.cs Näytä tiedosto

@@ -128,7 +128,7 @@ namespace DotNetCore.CAP.Dashboard
Routes.AddRazorPage("/nodes", x =>
{
var id = x.Request.Cookies["cap.node"];
var id = x.Request.Cookies.ContainsKey("cap.node") ? x.Request.Cookies["cap.node"] : string.Empty;
return new NodePage(id);
});



+ 10
- 16
src/DotNetCore.CAP.MySql/IDataStorage.MySql.cs Näytä tiedosto

@@ -141,22 +141,11 @@ namespace DotNetCore.CAP.MySql
new MySqlParameter("@timeout", timeout), new MySqlParameter("@batchCount", batchCount));
}

public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry()
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql = $"SELECT * FROM `{_pubName}` WHERE `Retries`<{_capOptions.Value.FailedRetryCount} AND `Version`='{_capOptions.Value.Version}' AND `Added`<'{fourMinAgo}' AND (`StatusName` = '{StatusName.Failed}' OR `StatusName` = '{StatusName.Scheduled}') LIMIT 200;";

return await GetMessagesOfNeedRetryAsync(sql);
}

public async Task<IEnumerable<MediumMessage>> GetReceivedMessagesOfNeedRetry()
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql =
$"SELECT * FROM `{_recName}` WHERE `Retries`<{_capOptions.Value.FailedRetryCount} AND `Version`='{_capOptions.Value.Version}' AND `Added`<'{fourMinAgo}' AND (`StatusName` = '{StatusName.Failed}' OR `StatusName` = '{StatusName.Scheduled}') LIMIT 200;";
public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry() =>
await GetMessagesOfNeedRetryAsync(_pubName);

return await GetMessagesOfNeedRetryAsync(sql);
}
public async Task<IEnumerable<MediumMessage>> GetReceivedMessagesOfNeedRetry() =>
await GetMessagesOfNeedRetryAsync(_recName);

public IMonitoringApi GetMonitoringApi()
{
@@ -189,8 +178,13 @@ namespace DotNetCore.CAP.MySql
connection.ExecuteNonQuery(sql, sqlParams: sqlParams);
}

private async Task<IEnumerable<MediumMessage>> GetMessagesOfNeedRetryAsync(string sql)
private async Task<IEnumerable<MediumMessage>> GetMessagesOfNeedRetryAsync(string tableName)
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql =
$"SELECT `Id`,`Content`,`Retries`,`Added` FROM `{tableName}` WHERE `Retries`<{_capOptions.Value.FailedRetryCount} " +
$"AND `Version`='{_capOptions.Value.Version}' AND `Added`<'{fourMinAgo}' AND (`StatusName` = '{StatusName.Failed}' OR `StatusName` = '{StatusName.Scheduled}') LIMIT 200;";

await using var connection = new MySqlConnection(_options.Value.ConnectionString);
var result = connection.ExecuteReader(sql, reader =>
{


+ 10
- 17
src/DotNetCore.CAP.PostgreSql/IDataStorage.PostgreSql.cs Näytä tiedosto

@@ -143,23 +143,11 @@ namespace DotNetCore.CAP.PostgreSql
return await Task.FromResult(count);
}

public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry()
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql =
$"SELECT * FROM {_pubName} WHERE \"Retries\"<{_capOptions.Value.FailedRetryCount} AND \"Version\"='{_capOptions.Value.Version}' AND \"Added\"<'{fourMinAgo}' AND (\"StatusName\"='{StatusName.Failed}' OR \"StatusName\"='{StatusName.Scheduled}') LIMIT 200;";
public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry() =>
await GetMessagesOfNeedRetryAsync(_pubName);

return await GetMessagesOfNeedRetryAsync(sql);
}

public async Task<IEnumerable<MediumMessage>> GetReceivedMessagesOfNeedRetry()
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql =
$"SELECT * FROM {_recName} WHERE \"Retries\"<{_capOptions.Value.FailedRetryCount} AND \"Version\"='{_capOptions.Value.Version}' AND \"Added\"<'{fourMinAgo}' AND (\"StatusName\"='{StatusName.Failed}' OR \"StatusName\"='{StatusName.Scheduled}') LIMIT 200;";

return await GetMessagesOfNeedRetryAsync(sql);
}
public async Task<IEnumerable<MediumMessage>> GetReceivedMessagesOfNeedRetry() =>
await GetMessagesOfNeedRetryAsync(_recName);

public IMonitoringApi GetMonitoringApi()
{
@@ -195,8 +183,13 @@ namespace DotNetCore.CAP.PostgreSql
connection.ExecuteNonQuery(sql, sqlParams: sqlParams);
}

private async Task<IEnumerable<MediumMessage>> GetMessagesOfNeedRetryAsync(string sql)
private async Task<IEnumerable<MediumMessage>> GetMessagesOfNeedRetryAsync(string tableName)
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql =
$"SELECT \"Id\",\"Content\",\"Retries\",\"Added\" FROM {tableName} WHERE \"Retries\"<{_capOptions.Value.FailedRetryCount} " +
$"AND \"Version\"='{_capOptions.Value.Version}' AND \"Added\"<'{fourMinAgo}' AND (\"StatusName\"='{StatusName.Failed}' OR \"StatusName\"='{StatusName.Scheduled}') LIMIT 200;";

await using var connection = new NpgsqlConnection(_options.Value.ConnectionString);
var result = connection.ExecuteReader(sql, reader =>
{


+ 10
- 18
src/DotNetCore.CAP.SqlServer/IDataStorage.SqlServer.cs Näytä tiedosto

@@ -142,24 +142,11 @@ namespace DotNetCore.CAP.SqlServer
return await Task.FromResult(count);
}

public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry()
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql = $"SELECT TOP (200) Id, Content, Retries, Added FROM {_pubName} WITH (readpast) WHERE Retries<{_capOptions.Value.FailedRetryCount} " +
$"AND Version='{_capOptions.Value.Version}' AND Added<'{fourMinAgo}' AND (StatusName = '{StatusName.Failed}' OR StatusName = '{StatusName.Scheduled}')";

return await GetMessagesOfNeedRetryAsync(sql);
}

public async Task<IEnumerable<MediumMessage>> GetReceivedMessagesOfNeedRetry()
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql =
$"SELECT TOP (200) Id, Content, Retries, Added FROM {_recName} WITH (readpast) WHERE Retries<{_capOptions.Value.FailedRetryCount} " +
$"AND Version='{_capOptions.Value.Version}' AND Added<'{fourMinAgo}' AND (StatusName = '{StatusName.Failed}' OR StatusName = '{StatusName.Scheduled}')";
public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry() =>
await GetMessagesOfNeedRetryAsync(_pubName);

return await GetMessagesOfNeedRetryAsync(sql);
}
public async Task<IEnumerable<MediumMessage>> GetReceivedMessagesOfNeedRetry() =>
await GetMessagesOfNeedRetryAsync(_recName);

public IMonitoringApi GetMonitoringApi()
{
@@ -195,8 +182,13 @@ namespace DotNetCore.CAP.SqlServer
connection.ExecuteNonQuery(sql, sqlParams: sqlParams);
}

private async Task<IEnumerable<MediumMessage>> GetMessagesOfNeedRetryAsync(string sql)
private async Task<IEnumerable<MediumMessage>> GetMessagesOfNeedRetryAsync(string tableName)
{
var fourMinAgo = DateTime.Now.AddMinutes(-4).ToString("O");
var sql =
$"SELECT TOP (200) Id, Content, Retries, Added FROM {tableName} WITH (readpast) WHERE Retries<{_capOptions.Value.FailedRetryCount} " +
$"AND Version='{_capOptions.Value.Version}' AND Added<'{fourMinAgo}' AND (StatusName = '{StatusName.Failed}' OR StatusName = '{StatusName.Scheduled}')";

List<MediumMessage> result;
using (var connection = new SqlConnection(_options.Value.ConnectionString))
{


+ 1
- 1
src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs Näytä tiedosto

@@ -193,7 +193,7 @@ with aggr as (
where StatusName = @statusName
group by replace(convert(varchar, Added, 111), '/','-') + '-' + CONVERT(varchar, DATEPART(hh, Added))
)
select [Key], [Count] from aggr with (nolock) where [Key] in @keys;";
select [Key], [Count] from aggr with (nolock) where [Key] >= @minKey and [Key] <= @maxKey;";

//SQL Server 2012+
var sqlQuery = $@"


Ladataan…
Peruuta
Tallenna