Fixed the issue where MySql was sometimes throwing errors about not being able to execute the retry strat

pull/4016/head
tidusjar 4 years ago
parent f50536c005
commit 530e55a39f

@ -76,6 +76,9 @@ namespace Ombi.Schedule.Jobs.Couchpotato
_log.LogInformation(LoggingEvents.CouchPotatoCacher, "Getting all active movies from CP"); _log.LogInformation(LoggingEvents.CouchPotatoCacher, "Getting all active movies from CP");
var movies = await _api.GetMovies(settings.FullUri, settings.ApiKey, new[] {"active"}); var movies = await _api.GetMovies(settings.FullUri, settings.ApiKey, new[] {"active"});
if (movies != null) if (movies != null)
{
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{ {
// Let's remove the old cached data // Let's remove the old cached data
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
@ -83,6 +86,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM CouchPotatoCache"); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM CouchPotatoCache");
tran.Commit(); tran.Commit();
} }
});
// Save // Save
var movieIds = new List<CouchPotatoCache>(); var movieIds = new List<CouchPotatoCache>();
@ -102,7 +106,9 @@ namespace Ombi.Schedule.Jobs.Couchpotato
_log.LogError("TMDBId is not > 0 for movie {0}", m.title); _log.LogError("TMDBId is not > 0 for movie {0}", m.title);
} }
} }
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.CouchPotatoCache.AddRangeAsync(movieIds); await _ctx.CouchPotatoCache.AddRangeAsync(movieIds);
@ -110,6 +116,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato
await _ctx.SaveChangesAsync(); await _ctx.SaveChangesAsync();
tran.Commit(); tran.Commit();
} }
});
await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) await _notification.Clients.Clients(NotificationHub.AdminConnectionIds)
.SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Finished"); .SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Finished");

@ -50,6 +50,9 @@ namespace Ombi.Schedule.Jobs.Lidarr
{ {
var albums = await _lidarrApi.GetAllAlbums(settings.ApiKey, settings.FullUri); var albums = await _lidarrApi.GetAllAlbums(settings.ApiKey, settings.FullUri);
if (albums != null && albums.Any()) if (albums != null && albums.Any())
{
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{ {
// Let's remove the old cached data // Let's remove the old cached data
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
@ -57,6 +60,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrAlbumCache"); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrAlbumCache");
tran.Commit(); tran.Commit();
} }
});
var albumCache = new List<LidarrAlbumCache>(); var albumCache = new List<LidarrAlbumCache>();
foreach (var a in albums) foreach (var a in albums)
@ -76,7 +80,9 @@ namespace Ombi.Schedule.Jobs.Lidarr
}); });
} }
} }
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.LidarrAlbumCache.AddRangeAsync(albumCache); await _ctx.LidarrAlbumCache.AddRangeAsync(albumCache);
@ -84,6 +90,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
await _ctx.SaveChangesAsync(); await _ctx.SaveChangesAsync();
tran.Commit(); tran.Commit();
} }
});
} }
} }
catch (System.Exception ex) catch (System.Exception ex)

@ -49,6 +49,9 @@ namespace Ombi.Schedule.Jobs.Lidarr
{ {
var artists = await _lidarrApi.GetArtists(settings.ApiKey, settings.FullUri); var artists = await _lidarrApi.GetArtists(settings.ApiKey, settings.FullUri);
if (artists != null && artists.Any()) if (artists != null && artists.Any())
{
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{ {
// Let's remove the old cached data // Let's remove the old cached data
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
@ -56,6 +59,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrArtistCache"); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrArtistCache");
tran.Commit(); tran.Commit();
} }
});
var artistCache = new List<LidarrArtistCache>(); var artistCache = new List<LidarrArtistCache>();
foreach (var a in artists) foreach (var a in artists)
@ -71,7 +75,9 @@ namespace Ombi.Schedule.Jobs.Lidarr
}); });
} }
} }
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.LidarrArtistCache.AddRangeAsync(artistCache); await _ctx.LidarrArtistCache.AddRangeAsync(artistCache);
@ -79,6 +85,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
await _ctx.SaveChangesAsync(); await _ctx.SaveChangesAsync();
tran.Commit(); tran.Commit();
} }
});
} }
} }
catch (Exception ex) catch (Exception ex)

@ -45,6 +45,9 @@ namespace Ombi.Schedule.Jobs.Radarr
{ {
var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri); var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);
if (movies != null) if (movies != null)
{
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{ {
// Let's remove the old cached data // Let's remove the old cached data
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
@ -52,6 +55,7 @@ namespace Ombi.Schedule.Jobs.Radarr
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM RadarrCache"); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM RadarrCache");
tran.Commit(); tran.Commit();
} }
});
var movieIds = new List<RadarrCache>(); var movieIds = new List<RadarrCache>();
foreach (var m in movies) foreach (var m in movies)
@ -72,7 +76,9 @@ namespace Ombi.Schedule.Jobs.Radarr
} }
} }
} }
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.RadarrCache.AddRangeAsync(movieIds); await _ctx.RadarrCache.AddRangeAsync(movieIds);
@ -80,6 +86,7 @@ namespace Ombi.Schedule.Jobs.Radarr
await _ctx.SaveChangesAsync(); await _ctx.SaveChangesAsync();
tran.Commit(); tran.Commit();
} }
});
} }
await OmbiQuartz.TriggerJob(nameof(IArrAvailabilityChecker), "DVR"); await OmbiQuartz.TriggerJob(nameof(IArrAvailabilityChecker), "DVR");

@ -46,11 +46,15 @@ namespace Ombi.Schedule.Jobs.SickRage
{ {
var srShows = shows.data.Values; var srShows = shows.data.Values;
var ids = srShows.Select(x => x.tvdbid); var ids = srShows.Select(x => x.tvdbid);
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SickRageCache"); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SickRageCache");
tran.Commit(); tran.Commit();
} }
});
var entites = ids.Select(id => new SickRageCache { TvDbId = id }).ToList(); var entites = ids.Select(id => new SickRageCache { TvDbId = id }).ToList();
@ -77,13 +81,16 @@ namespace Ombi.Schedule.Jobs.SickRage
} }
} }
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.SickRageEpisodeCache.AddRangeAsync(episodesToAdd); await _ctx.SickRageEpisodeCache.AddRangeAsync(episodesToAdd);
await _ctx.SaveChangesAsync(); await _ctx.SaveChangesAsync();
tran.Commit(); tran.Commit();
} }
});
} }
} }
catch (Exception e) catch (Exception e)

@ -49,11 +49,15 @@ namespace Ombi.Schedule.Jobs.Sonarr
{ {
var sonarrSeries = series as ImmutableHashSet<SonarrSeries> ?? series.ToImmutableHashSet(); var sonarrSeries = series as ImmutableHashSet<SonarrSeries> ?? series.ToImmutableHashSet();
var ids = sonarrSeries.Select(x => x.tvdbId); var ids = sonarrSeries.Select(x => x.tvdbId);
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache"); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache");
tran.Commit(); tran.Commit();
} }
});
var existingSeries = await _ctx.SonarrCache.Select(x => x.TvDbId).ToListAsync(); var existingSeries = await _ctx.SonarrCache.Select(x => x.TvDbId).ToListAsync();
@ -62,11 +66,15 @@ namespace Ombi.Schedule.Jobs.Sonarr
await _ctx.SonarrCache.AddRangeAsync(entites); await _ctx.SonarrCache.AddRangeAsync(entites);
entites.Clear(); entites.Clear();
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache"); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache");
tran.Commit(); tran.Commit();
} }
});
foreach (var s in sonarrSeries) foreach (var s in sonarrSeries)
{ {
@ -116,7 +124,9 @@ namespace Ombi.Schedule.Jobs.Sonarr
// } // }
//} //}
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync()) using (var tran = await _ctx.Database.BeginTransactionAsync())
{ {
await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd); await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd);
@ -124,6 +134,7 @@ namespace Ombi.Schedule.Jobs.Sonarr
await _ctx.SaveChangesAsync(); await _ctx.SaveChangesAsync();
tran.Commit(); tran.Commit();
} }
});
} }
} }

@ -23,8 +23,6 @@ namespace Ombi.Store.Repository
} }
public async Task Record(AuditType type, AuditArea area, string description, string user) public async Task Record(AuditType type, AuditArea area, string description, string user)
{
using (var tran = await Ctx.Database.BeginTransactionAsync())
{ {
await Ctx.Audit.AddAsync(new Audit await Ctx.Audit.AddAsync(new Audit
{ {
@ -36,8 +34,6 @@ namespace Ombi.Store.Repository
}); });
await Ctx.SaveChangesAsync(); await Ctx.SaveChangesAsync();
tran.Commit();
}
} }
} }
} }

@ -93,12 +93,16 @@ namespace Ombi
Type = ConfigurationTypes.Url, Type = ConfigurationTypes.Url,
Value = "http://*:5000" Value = "http://*:5000"
}; };
var strat = settingsDb.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await settingsDb.Database.BeginTransactionAsync()) using (var tran = await settingsDb.Database.BeginTransactionAsync())
{ {
settingsDb.ApplicationConfigurations.Add(url); settingsDb.ApplicationConfigurations.Add(url);
await settingsDb.SaveChangesAsync(); await settingsDb.SaveChangesAsync();
await tran.CommitAsync(); await tran.CommitAsync();
} }
});
urlValue = url.Value; urlValue = url.Value;
} }
@ -106,12 +110,15 @@ namespace Ombi
if (!url.Value.Equals(host)) if (!url.Value.Equals(host))
{ {
url.Value = UrlArgs; url.Value = UrlArgs;
var strat = settingsDb.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await settingsDb.Database.BeginTransactionAsync()) using (var tran = await settingsDb.Database.BeginTransactionAsync())
{ {
await settingsDb.SaveChangesAsync(); await settingsDb.SaveChangesAsync();
await tran.CommitAsync(); await tran.CommitAsync();
} }
});
urlValue = url.Value; urlValue = url.Value;
} }
@ -129,24 +136,30 @@ namespace Ombi
Type = ConfigurationTypes.BaseUrl, Type = ConfigurationTypes.BaseUrl,
Value = baseUrl Value = baseUrl
}; };
var strat = settingsDb.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await settingsDb.Database.BeginTransactionAsync()) using (var tran = await settingsDb.Database.BeginTransactionAsync())
{ {
settingsDb.ApplicationConfigurations.Add(dbBaseUrl); settingsDb.ApplicationConfigurations.Add(dbBaseUrl);
await settingsDb.SaveChangesAsync(); await settingsDb.SaveChangesAsync();
await tran.CommitAsync(); await tran.CommitAsync();
} }
});
} }
} }
else if (baseUrl.HasValue() && !baseUrl.Equals(dbBaseUrl.Value)) else if (baseUrl.HasValue() && !baseUrl.Equals(dbBaseUrl.Value))
{ {
dbBaseUrl.Value = baseUrl; dbBaseUrl.Value = baseUrl;
var strat = settingsDb.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await settingsDb.Database.BeginTransactionAsync()) using (var tran = await settingsDb.Database.BeginTransactionAsync())
{ {
await settingsDb.SaveChangesAsync(); await settingsDb.SaveChangesAsync();
await tran.CommitAsync(); await tran.CommitAsync();
} }
});
} }
Console.WriteLine($"We are running on {urlValue}"); Console.WriteLine($"We are running on {urlValue}");
@ -164,13 +177,16 @@ namespace Ombi
Type = ConfigurationTypes.SecurityToken, Type = ConfigurationTypes.SecurityToken,
Value = Guid.NewGuid().ToString("N") Value = Guid.NewGuid().ToString("N")
}; };
var strat = ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await ctx.Database.BeginTransactionAsync()) using (var tran = await ctx.Database.BeginTransactionAsync())
{ {
ctx.ApplicationConfigurations.Add(securityToken); ctx.ApplicationConfigurations.Add(securityToken);
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
await tran.CommitAsync(); await tran.CommitAsync();
} }
});
} }
instance.SecurityKey = securityToken.Value; instance.SecurityKey = securityToken.Value;

Loading…
Cancel
Save