Commit c15ae317 authored by Savorboard's avatar Savorboard

Rename file

parent c4f4f5f4
using System; // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Threading; using System.Threading;
...@@ -28,8 +31,8 @@ namespace DotNetCore.CAP.MySql ...@@ -28,8 +31,8 @@ namespace DotNetCore.CAP.MySql
public async Task ChangePublishStateAsync(MediumMessage message, StatusName state) public async Task ChangePublishStateAsync(MediumMessage message, StatusName state)
{ {
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using var connection = new MySqlConnection(_options.Value.ConnectionString);
{
var sql = $"UPDATE `{_options.Value.TableNamePrefix}.published` SET `Retries` = @Retries,`ExpiresAt` = @ExpiresAt,`StatusName`=@StatusName WHERE `Id`=@Id;"; var sql = $"UPDATE `{_options.Value.TableNamePrefix}.published` SET `Retries` = @Retries,`ExpiresAt` = @ExpiresAt,`StatusName`=@StatusName WHERE `Id`=@Id;";
await connection.ExecuteAsync(sql, new await connection.ExecuteAsync(sql, new
...@@ -40,12 +43,11 @@ namespace DotNetCore.CAP.MySql ...@@ -40,12 +43,11 @@ namespace DotNetCore.CAP.MySql
StatusName = state.ToString("G") StatusName = state.ToString("G")
}); });
} }
}
public async Task ChangeReceiveStateAsync(MediumMessage message, StatusName state) public async Task ChangeReceiveStateAsync(MediumMessage message, StatusName state)
{ {
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using var connection = new MySqlConnection(_options.Value.ConnectionString);
{
var sql = $"UPDATE `{_options.Value.TableNamePrefix}.received` SET `Retries` = @Retries,`ExpiresAt` = @ExpiresAt,`StatusName`=@StatusName WHERE `Id`=@Id;"; var sql = $"UPDATE `{_options.Value.TableNamePrefix}.received` SET `Retries` = @Retries,`ExpiresAt` = @ExpiresAt,`StatusName`=@StatusName WHERE `Id`=@Id;";
await connection.ExecuteAsync(sql, new await connection.ExecuteAsync(sql, new
...@@ -56,7 +58,6 @@ namespace DotNetCore.CAP.MySql ...@@ -56,7 +58,6 @@ namespace DotNetCore.CAP.MySql
StatusName = state.ToString("G") StatusName = state.ToString("G")
}); });
} }
}
public async Task<MediumMessage> StoreMessageAsync(string name, Message content, object dbTransaction = null, CancellationToken cancellationToken = default) public async Task<MediumMessage> StoreMessageAsync(string name, Message content, object dbTransaction = null, CancellationToken cancellationToken = default)
{ {
...@@ -85,11 +86,9 @@ namespace DotNetCore.CAP.MySql ...@@ -85,11 +86,9 @@ namespace DotNetCore.CAP.MySql
if (dbTransaction == null) if (dbTransaction == null)
{ {
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using var connection = new MySqlConnection(_options.Value.ConnectionString);
{
await connection.ExecuteAsync(sql, po); await connection.ExecuteAsync(sql, po);
} }
}
else else
{ {
var dbTrans = dbTransaction as IDbTransaction; var dbTrans = dbTransaction as IDbTransaction;
...@@ -109,12 +108,11 @@ namespace DotNetCore.CAP.MySql ...@@ -109,12 +108,11 @@ namespace DotNetCore.CAP.MySql
{ {
var sql = $@"INSERT INTO `{_options.Value.TableNamePrefix}.received`(`Id`,`Version`,`Name`,`Group`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`) VALUES(@Id,'{_options.Value.Version}',@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; var sql = $@"INSERT INTO `{_options.Value.TableNamePrefix}.received`(`Id`,`Version`,`Name`,`Group`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`) VALUES(@Id,'{_options.Value.Version}',@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using var connection = new MySqlConnection(_options.Value.ConnectionString);
{
await connection.ExecuteAsync(sql, new await connection.ExecuteAsync(sql, new
{ {
Id = SnowflakeId.Default().NextId().ToString(), Id = SnowflakeId.Default().NextId().ToString(),
Group = group, Group = @group,
Name = name, Name = name,
Content = content, Content = content,
Retries = _capOptions.Value.FailedRetryCount, Retries = _capOptions.Value.FailedRetryCount,
...@@ -123,9 +121,8 @@ namespace DotNetCore.CAP.MySql ...@@ -123,9 +121,8 @@ namespace DotNetCore.CAP.MySql
StatusName = nameof(StatusName.Failed) StatusName = nameof(StatusName.Failed)
}); });
} }
}
public Task<MediumMessage> StoreReceivedMessageAsync(string name, string group, Message message) public async Task<MediumMessage> StoreReceivedMessageAsync(string name, string group, Message message)
{ {
var sql = $@"INSERT INTO `{_options.Value.TableNamePrefix}.received`(`Id`,`Version`,`Name`,`Group`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`) VALUES(@Id,'{_options.Value.Version}',@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; var sql = $@"INSERT INTO `{_options.Value.TableNamePrefix}.received`(`Id`,`Version`,`Name`,`Group`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`) VALUES(@Id,'{_options.Value.Version}',@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
...@@ -138,13 +135,11 @@ namespace DotNetCore.CAP.MySql ...@@ -138,13 +135,11 @@ namespace DotNetCore.CAP.MySql
Retries = 0 Retries = 0
}; };
var content = StringSerializer.Serialize(mdMessage.Origin); var content = StringSerializer.Serialize(mdMessage.Origin);
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using var connection = new MySqlConnection(_options.Value.ConnectionString);
{ await connection.ExecuteAsync(sql, new
connection.Execute(sql, new
{ {
Id = mdMessage.DbId, Id = mdMessage.DbId,
Group = group, Group = @group,
Name = name, Name = name,
Content = content, Content = content,
mdMessage.Retries, mdMessage.Retries,
...@@ -152,20 +147,17 @@ namespace DotNetCore.CAP.MySql ...@@ -152,20 +147,17 @@ namespace DotNetCore.CAP.MySql
mdMessage.ExpiresAt, mdMessage.ExpiresAt,
StatusName = nameof(StatusName.Scheduled) StatusName = nameof(StatusName.Scheduled)
}); });
} return mdMessage;
return Task.FromResult(mdMessage);
} }
public async Task<int> DeleteExpiresAsync(string table, DateTime timeout, int batchCount = 1000, CancellationToken token = default) public async Task<int> DeleteExpiresAsync(string table, DateTime timeout, int batchCount = 1000, CancellationToken token = default)
{ {
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using var connection = new MySqlConnection(_options.Value.ConnectionString);
{
return await connection.ExecuteAsync( return await connection.ExecuteAsync(
$@"DELETE FROM `{table}` WHERE ExpiresAt < @timeout limit @batchCount;", $@"DELETE FROM `{table}` WHERE ExpiresAt < @timeout limit @batchCount;",
new { timeout, batchCount }); new { timeout, batchCount });
} }
}
public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry() public async Task<IEnumerable<MediumMessage>> GetPublishedMessagesOfNeedRetry()
{ {
...@@ -173,8 +165,7 @@ namespace DotNetCore.CAP.MySql ...@@ -173,8 +165,7 @@ namespace DotNetCore.CAP.MySql
var sql = $"SELECT * FROM `{_options.Value.TableNamePrefix}.published` WHERE `Retries`<{_capOptions.Value.FailedRetryCount} AND `Version`='{_capOptions.Value.Version}' AND `Added`<'{fourMinAgo}' AND (`StatusName` = '{StatusName.Failed}' OR `StatusName` = '{StatusName.Scheduled}') LIMIT 200;"; var sql = $"SELECT * FROM `{_options.Value.TableNamePrefix}.published` WHERE `Retries`<{_capOptions.Value.FailedRetryCount} AND `Version`='{_capOptions.Value.Version}' AND `Added`<'{fourMinAgo}' AND (`StatusName` = '{StatusName.Failed}' OR `StatusName` = '{StatusName.Scheduled}') LIMIT 200;";
var result = new List<MediumMessage>(); var result = new List<MediumMessage>();
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using var connection = new MySqlConnection(_options.Value.ConnectionString);
{
var reader = await connection.ExecuteReaderAsync(sql); var reader = await connection.ExecuteReaderAsync(sql);
while (reader.Read()) while (reader.Read())
{ {
...@@ -186,7 +177,6 @@ namespace DotNetCore.CAP.MySql ...@@ -186,7 +177,6 @@ namespace DotNetCore.CAP.MySql
Added = reader.GetDateTime(5) Added = reader.GetDateTime(5)
}); });
} }
}
return result; return result;
} }
...@@ -197,8 +187,8 @@ namespace DotNetCore.CAP.MySql ...@@ -197,8 +187,8 @@ namespace DotNetCore.CAP.MySql
$"SELECT * FROM `{_options.Value.TableNamePrefix}.received` WHERE `Retries`<{_capOptions.Value.FailedRetryCount} AND `Version`='{_capOptions.Value.Version}' AND `Added`<'{fourMinAgo}' AND (`StatusName` = '{StatusName.Failed}' OR `StatusName` = '{StatusName.Scheduled}') LIMIT 200;"; $"SELECT * FROM `{_options.Value.TableNamePrefix}.received` WHERE `Retries`<{_capOptions.Value.FailedRetryCount} AND `Version`='{_capOptions.Value.Version}' AND `Added`<'{fourMinAgo}' AND (`StatusName` = '{StatusName.Failed}' OR `StatusName` = '{StatusName.Scheduled}') LIMIT 200;";
var result = new List<MediumMessage>(); var result = new List<MediumMessage>();
using (var connection = new MySqlConnection(_options.Value.ConnectionString))
{ await using var connection = new MySqlConnection(_options.Value.ConnectionString);
var reader = await connection.ExecuteReaderAsync(sql); var reader = await connection.ExecuteReaderAsync(sql);
while (reader.Read()) while (reader.Read())
{ {
...@@ -210,7 +200,7 @@ namespace DotNetCore.CAP.MySql ...@@ -210,7 +200,7 @@ namespace DotNetCore.CAP.MySql
Added = reader.GetDateTime(5) Added = reader.GetDateTime(5)
}); });
} }
}
return result; return result;
} }
......
// Copyright (c) .NET Core Community. All rights reserved. // Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dapper; using Dapper;
...@@ -18,8 +19,7 @@ namespace DotNetCore.CAP.MySql ...@@ -18,8 +19,7 @@ namespace DotNetCore.CAP.MySql
public MySqlStorageInitializer( public MySqlStorageInitializer(
ILogger<MySqlStorageInitializer> logger, ILogger<MySqlStorageInitializer> logger,
IOptions<MySqlOptions> options, IOptions<MySqlOptions> options)
IOptions<CapOptions> capOptions)
{ {
_options = options; _options = options;
_logger = logger; _logger = logger;
...@@ -43,7 +43,7 @@ namespace DotNetCore.CAP.MySql ...@@ -43,7 +43,7 @@ namespace DotNetCore.CAP.MySql
} }
var sql = CreateDbTablesScript(_options.Value.TableNamePrefix); var sql = CreateDbTablesScript(_options.Value.TableNamePrefix);
using (var connection = new MySqlConnection(_options.Value.ConnectionString)) await using (var connection = new MySqlConnection(_options.Value.ConnectionString))
{ {
await connection.ExecuteAsync(sql); await connection.ExecuteAsync(sql);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment