mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 04:49:33 -07:00
Retry database connections (#5124)
* Retry database connections * build: fix pr pipeline * build: fix docker img * change the build image to SDK * update codeql * v3 * fixy
This commit is contained in:
parent
af8b519b46
commit
38f7ced860
4 changed files with 38 additions and 9 deletions
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
|
@ -37,7 +37,7 @@ jobs:
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v3
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
@ -48,7 +48,7 @@ jobs:
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v3
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
|
@ -62,4 +62,4 @@ jobs:
|
||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v3
|
||||||
|
|
4
.github/workflows/pr.yml
vendored
4
.github/workflows/pr.yml
vendored
|
@ -76,10 +76,10 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: win10-x64
|
- os: win-x64
|
||||||
format: zip
|
format: zip
|
||||||
compression: zip
|
compression: zip
|
||||||
- os: win10-x86
|
- os: win-x86
|
||||||
format: zip
|
format: zip
|
||||||
compression: zip
|
compression: zip
|
||||||
- os: linux-x64
|
- os: linux-x64
|
||||||
|
|
|
@ -3,11 +3,14 @@ using System.IO;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using MySqlConnector;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
using Ombi.Store.Context;
|
using Ombi.Store.Context;
|
||||||
using Ombi.Store.Context.MySql;
|
using Ombi.Store.Context.MySql;
|
||||||
using Ombi.Store.Context.Sqlite;
|
using Ombi.Store.Context.Sqlite;
|
||||||
|
using Polly;
|
||||||
|
using Pomelo.EntityFrameworkCore.MySql.Storage.Internal;
|
||||||
using SQLitePCL;
|
using SQLitePCL;
|
||||||
|
|
||||||
namespace Ombi.Extensions
|
namespace Ombi.Extensions
|
||||||
|
@ -120,13 +123,40 @@ namespace Ombi.Extensions
|
||||||
|
|
||||||
public static void ConfigureMySql(DbContextOptionsBuilder options, PerDatabaseConfiguration config)
|
public static void ConfigureMySql(DbContextOptionsBuilder options, PerDatabaseConfiguration config)
|
||||||
{
|
{
|
||||||
options.UseMySql(config.ConnectionString, ServerVersion.AutoDetect(config.ConnectionString), b =>
|
if (string.IsNullOrEmpty(config.ConnectionString))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("ConnectionString for the MySql/Mariadb database is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
options.UseMySql(config.ConnectionString, GetServerVersion(config.ConnectionString), b =>
|
||||||
{
|
{
|
||||||
//b.CharSetBehavior(Pomelo.EntityFrameworkCore.MySql.Infrastructure.CharSetBehavior.NeverAppend); // ##ISSUE, link to migrations?
|
//b.CharSetBehavior(Pomelo.EntityFrameworkCore.MySql.Infrastructure.CharSetBehavior.NeverAppend); // ##ISSUE, link to migrations?
|
||||||
b.EnableRetryOnFailure();
|
b.EnableRetryOnFailure();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ServerVersion GetServerVersion(string connectionString)
|
||||||
|
{
|
||||||
|
// Workaround Windows bug, that can lead to the following exception:
|
||||||
|
//
|
||||||
|
// MySqlConnector.MySqlException (0x80004005): SSL Authentication Error
|
||||||
|
// ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
|
||||||
|
// ---> System.ComponentModel.Win32Exception (0x8009030F): The message or signature supplied for verification has been altered
|
||||||
|
//
|
||||||
|
// See https://github.com/dotnet/runtime/issues/17005#issuecomment-305848835
|
||||||
|
//
|
||||||
|
// Also workaround for the fact, that ServerVersion.AutoDetect() does not use any retrying strategy.
|
||||||
|
ServerVersion serverVersion = null;
|
||||||
|
#pragma warning disable EF1001
|
||||||
|
var retryPolicy = Policy.Handle<Exception>(exception => MySqlTransientExceptionDetector.ShouldRetryOn(exception))
|
||||||
|
#pragma warning restore EF1001
|
||||||
|
.WaitAndRetry(3, (count, context) => TimeSpan.FromMilliseconds(count * 250));
|
||||||
|
|
||||||
|
serverVersion = retryPolicy.Execute(() => serverVersion = ServerVersion.AutoDetect(connectionString));
|
||||||
|
|
||||||
|
return serverVersion;
|
||||||
|
}
|
||||||
|
|
||||||
public class DatabaseConfiguration
|
public class DatabaseConfiguration
|
||||||
{
|
{
|
||||||
public DatabaseConfiguration()
|
public DatabaseConfiguration()
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# build stage
|
# build stage
|
||||||
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-jammy-chiseled AS build
|
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
|
||||||
LABEL exclaimer-signature-analytics-build=true
|
|
||||||
ARG VERSION=1.0.0
|
ARG VERSION=1.0.0
|
||||||
WORKDIR /source
|
WORKDIR /source
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ FROM build AS publish
|
||||||
|
|
||||||
RUN dotnet publish "Ombi.csproj" -c release --no-restore --no-build -o /app/publish
|
RUN dotnet publish "Ombi.csproj" -c release --no-restore --no-build -o /app/publish
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled as base
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy as base
|
||||||
WORKDIR /src/Ombi
|
WORKDIR /src/Ombi
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue