mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-03 17:36:59 +01:00
wait a bit if can't connect to DB
This commit is contained in:
parent
171065f45c
commit
4be0b2c932
1 changed files with 24 additions and 1 deletions
|
@ -30,6 +30,7 @@ using BTCPayServer.Services.Mails;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using BTCPayServer.Models;
|
using BTCPayServer.Models;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace BTCPayServer.Hosting
|
namespace BTCPayServer.Hosting
|
||||||
{
|
{
|
||||||
|
@ -165,12 +166,34 @@ namespace BTCPayServer.Hosting
|
||||||
}
|
}
|
||||||
|
|
||||||
using(var scope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
|
using(var scope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
|
||||||
|
{
|
||||||
|
//Wait the DB is ready
|
||||||
|
Retry(() =>
|
||||||
{
|
{
|
||||||
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>().Database.Migrate();
|
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>().Database.Migrate();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
app.UseMiddleware<BTCPayMiddleware>();
|
app.UseMiddleware<BTCPayMiddleware>();
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Retry(Action act)
|
||||||
|
{
|
||||||
|
CancellationTokenSource cts = new CancellationTokenSource(10000);
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
act();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
if(cts.IsCancellationRequested)
|
||||||
|
throw;
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue