From 247d708e7acaa89e4fb50dbfcd15108e9fa35ed6 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 18 Oct 2017 08:24:19 +0100 Subject: [PATCH] Changed the way we download the .zip files in the auto updater #1460 This might make a difference to the permissions issue. but not 100% sure. Also lowered the retrying of jobs to default to 5, but updater to retry only once. --- .../Jobs/Ombi/OmbiAutomaticUpdater.cs | 21 ++++++++++++++++--- .../Interfaces}/IPlexAvailabilityChecker.cs | 0 .../{ => Interfaces}/IPlexUserImporter.cs | 0 src/Ombi/Controllers/IdentityController.cs | 3 --- src/Ombi/Startup.cs | 21 ++++++++++--------- 5 files changed, 29 insertions(+), 16 deletions(-) rename src/Ombi.Schedule/{ => Jobs/Plex/Interfaces}/IPlexAvailabilityChecker.cs (100%) rename src/Ombi.Schedule/Jobs/Plex/{ => Interfaces}/IPlexUserImporter.cs (100%) diff --git a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs index b3cf5b293..3193f9130 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs @@ -5,9 +5,11 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Net; +using System.Net.Http; using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Hangfire; using Hangfire.Console; using Hangfire.Server; using Microsoft.Extensions.Logging; @@ -52,6 +54,7 @@ namespace Ombi.Schedule.Jobs.Ombi } + [AutomaticRetry(Attempts = 1)] public async Task Update(PerformContext c) { Ctx = c; @@ -217,11 +220,23 @@ namespace Ombi.Schedule.Jobs.Ombi } } - public static async Task DownloadAsync(string requestUri, string filename, PerformContext ctx) + public async Task DownloadAsync(string requestUri, string filename, PerformContext ctx) { - using (var client = new WebClient()) + Logger.LogDebug("Starting the DownloadAsync"); + using (var client = new HttpClient()) { - await client.DownloadFileTaskAsync(requestUri, filename); + using (var result = await client.GetAsync(requestUri)) + { + if (result.IsSuccessStatusCode) + { + var contentStream = await result.Content.ReadAsStreamAsync(); + using (var stream = + new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)) + { + await contentStream.CopyToAsync(stream); + } + } + } } } } diff --git a/src/Ombi.Schedule/IPlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/Interfaces/IPlexAvailabilityChecker.cs similarity index 100% rename from src/Ombi.Schedule/IPlexAvailabilityChecker.cs rename to src/Ombi.Schedule/Jobs/Plex/Interfaces/IPlexAvailabilityChecker.cs diff --git a/src/Ombi.Schedule/Jobs/Plex/IPlexUserImporter.cs b/src/Ombi.Schedule/Jobs/Plex/Interfaces/IPlexUserImporter.cs similarity index 100% rename from src/Ombi.Schedule/Jobs/Plex/IPlexUserImporter.cs rename to src/Ombi.Schedule/Jobs/Plex/Interfaces/IPlexUserImporter.cs diff --git a/src/Ombi/Controllers/IdentityController.cs b/src/Ombi/Controllers/IdentityController.cs index 1b1447fd8..3e966fbcf 100644 --- a/src/Ombi/Controllers/IdentityController.cs +++ b/src/Ombi/Controllers/IdentityController.cs @@ -8,7 +8,6 @@ using AutoMapper; using Hangfire; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; @@ -20,7 +19,6 @@ using Ombi.Core.Claims; using Ombi.Core.Helpers; using Ombi.Core.Models.UI; using Ombi.Core.Settings; -using Ombi.Helpers; using Ombi.Models; using Ombi.Models.Identity; using Ombi.Notifications; @@ -29,7 +27,6 @@ using Ombi.Schedule.Jobs.Ombi; using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; -using Ombi.Store.Repository; using OmbiIdentityResult = Ombi.Models.Identity.IdentityResult; namespace Ombi.Controllers diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index e19971d48..4daeceb71 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -58,7 +58,7 @@ namespace Ombi .MinimumLevel.Information() .WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "Logs", "log-{Date}.txt")) - .WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Information) + .WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug) .CreateLogger(); } else @@ -67,7 +67,7 @@ namespace Ombi .MinimumLevel.Information() .WriteTo.RollingFile(Path.Combine(StoragePath.StoragePath, "Logs", "log-{Date}.txt")) - .WriteTo.SQLite(Path.Combine(StoragePath.StoragePath, "Ombi.db"), "Logs", LogEventLevel.Information) + .WriteTo.SQLite(Path.Combine(StoragePath.StoragePath, "Ombi.db"), "Logs", LogEventLevel.Debug) .CreateLogger(); } Log.Logger = config; @@ -92,7 +92,7 @@ namespace Ombi // Add framework services. services.AddDbContext(); - + services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders() @@ -105,9 +105,9 @@ namespace Ombi options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; - options.User.AllowedUserNameCharacters =string.Empty; + options.User.AllowedUserNameCharacters = string.Empty; }); - + services.AddMemoryCache(); services.AddJwtAuthentication(Configuration); @@ -131,7 +131,7 @@ namespace Ombi i.StoragePath = string.Empty; } var sqliteStorage = $"Data Source={Path.Combine(i.StoragePath, "Ombi.db")};"; - + services.AddHangfire(x => { x.UseSQLiteStorage(sqliteStorage); @@ -173,12 +173,13 @@ namespace Ombi app.UsePathBase(settings.BaseUrl); } - app.UseHangfireServer(new BackgroundJobServerOptions{WorkerCount = 1}); + app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1 }); app.UseHangfireDashboard(settings.BaseUrl.HasValue() ? $"{settings.BaseUrl}/hangfire" : "/hangfire", new DashboardOptions { - Authorization = new[] {new HangfireAuthorizationFilter()} + Authorization = new[] { new HangfireAuthorizationFilter() } }); + GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 3 }); // Setup the scheduler var jobSetup = app.ApplicationServices.GetService(); @@ -201,7 +202,7 @@ namespace Ombi c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.ShowJsonEditor(); }); - + app.UseMvc(routes => { routes.MapRoute( @@ -237,7 +238,7 @@ namespace Ombi else { var identity = new GenericIdentity("API"); - var principal = new GenericPrincipal(identity, new[] {"Admin", "ApiUser"}); + var principal = new GenericPrincipal(identity, new[] { "Admin", "ApiUser" }); context.User = principal; await next(); }