Add a internal retry when we have a locked db

pull/3016/head
Jamie Rees 6 years ago
parent b492b82e86
commit 08b7e8f540

@ -196,7 +196,7 @@ namespace Ombi.Schedule.Jobs.Plex
}
contentToAdd.Clear();
}
if (count > 200)
if (count > 30)
{
await Repo.SaveChangesAsync();
@ -233,7 +233,7 @@ namespace Ombi.Schedule.Jobs.Plex
}
contentToAdd.Clear();
}
if (count > 200)
if (count > 30)
{
await Repo.SaveChangesAsync();
}

@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Nito.AsyncEx" Version="5.0.0-pre-05" />
<PackageReference Include="Polly" Version="7.1.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="1.1.9" />
</ItemGroup>
<ItemGroup>

@ -3,11 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using Ombi.Helpers;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Polly;
namespace Ombi.Store.Repository
{
@ -83,7 +85,17 @@ namespace Ombi.Store.Repository
protected async Task<int> InternalSaveChanges()
{
return await _ctx.SaveChangesAsync();
var policy = Policy
.Handle<SqliteException>()
.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3)
});
var result = await policy.ExecuteAndCaptureAsync(async () => await _ctx.SaveChangesAsync());
return result.Result;
}

Loading…
Cancel
Save