Skip to content

Commit

Permalink
Increase SQL DB command timeouts to 3000 seconds everywhere in the co…
Browse files Browse the repository at this point in the history
…debase.
  • Loading branch information
giorgi1324 committed Nov 15, 2024
1 parent 3041587 commit 1a0e937
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/shared/Dapper/BaseDapperStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ namespace SharedContracts.Dapper;

public abstract class BaseDapperStorage(ILogger<IDataStorage> logger, PostgresConfiguration configuration)
{
private NpgsqlConnection CreateNpgsqlConnection()
{
var connectionStringBuilder = new NpgsqlConnectionStringBuilder(configuration.StorageConnectionString)
{
CommandTimeout = 3000,
};

return new(connectionStringBuilder.ConnectionString);
}
protected async Task ExecuteCommandAsync(Func<NpgsqlConnection, Task> operation, string errorMessage, CancellationToken cancellationToken = default)
{
try
{
await using var connection = new NpgsqlConnection(configuration.StorageConnectionString);
await using var connection = CreateNpgsqlConnection();
await connection.OpenAsync(cancellationToken);

await operation(connection);
Expand All @@ -21,7 +30,7 @@ protected async Task<TResult> ExecuteCommandAsync<TResult>(Func<NpgsqlConnection
{
try
{
await using var connection = new NpgsqlConnection(configuration.StorageConnectionString);
await using var connection = CreateNpgsqlConnection();
await connection.OpenAsync(cancellationToken);

var result = await operation(connection);
Expand All @@ -38,7 +47,7 @@ protected async Task<DapperResult<TResult, TFailure>> ExecuteCommandAsync<TResul
{
try
{
await using var connection = new NpgsqlConnection(configuration.StorageConnectionString);
await using var connection = CreateNpgsqlConnection();
await connection.OpenAsync(cancellationToken);

var result = await operation(connection);
Expand Down
7 changes: 6 additions & 1 deletion src/tissue/Features/DataProcessing/DapperDataStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public async Task DeleteTorrentsByInfoHashes(IReadOnlyCollection<string> infoHas

private async Task<NpgsqlConnection> CreateAndOpenConnection(CancellationToken cancellationToken = default)
{
var connection = new NpgsqlConnection(configuration.StorageConnectionString);
var connectionStringBuilder = new NpgsqlConnectionStringBuilder(configuration.StorageConnectionString)
{
CommandTimeout = 3000,
};

var connection = new NpgsqlConnection(connectionStringBuilder.ConnectionString);
await connection.OpenAsync(cancellationToken);
return connection;
}
Expand Down

0 comments on commit 1a0e937

Please sign in to comment.