From 35c24ad0ef64b9a09f1c43f5da99fdb1c1608744 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 25 Feb 2022 23:58:01 +0000 Subject: [PATCH] added job parallel lock, file structure, diagnostics --- Selector.CLI/Jobs/ScrobbleWatcherJob.cs | 1 + Selector.Web/Startup.cs | 2 +- Selector/Scrobble/{ => Mapping}/ScrobbleAlbumMapping.cs | 0 Selector/Scrobble/{ => Mapping}/ScrobbleArtistMapping.cs | 0 Selector/Scrobble/{ => Mapping}/ScrobbleMapping.cs | 5 +++++ Selector/Scrobble/{ => Mapping}/ScrobbleTrackMapping.cs | 0 Selector/Scrobble/ScrobbleRequest.cs | 6 ++++++ 7 files changed, 13 insertions(+), 1 deletion(-) rename Selector/Scrobble/{ => Mapping}/ScrobbleAlbumMapping.cs (100%) rename Selector/Scrobble/{ => Mapping}/ScrobbleArtistMapping.cs (100%) rename Selector/Scrobble/{ => Mapping}/ScrobbleMapping.cs (92%) rename Selector/Scrobble/{ => Mapping}/ScrobbleTrackMapping.cs (100%) diff --git a/Selector.CLI/Jobs/ScrobbleWatcherJob.cs b/Selector.CLI/Jobs/ScrobbleWatcherJob.cs index 1feb531..6c58783 100644 --- a/Selector.CLI/Jobs/ScrobbleWatcherJob.cs +++ b/Selector.CLI/Jobs/ScrobbleWatcherJob.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; namespace Selector.CLI.Jobs { + [DisallowConcurrentExecution] public class ScrobbleWatcherJob : IJob { private readonly ILogger logger; diff --git a/Selector.Web/Startup.cs b/Selector.Web/Startup.cs index af819a2..b39ca19 100644 --- a/Selector.Web/Startup.cs +++ b/Selector.Web/Startup.cs @@ -125,11 +125,11 @@ namespace Selector.Web if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseHttpsRedirection(); } else { app.UseExceptionHandler("/Error"); + app.UseHttpsRedirection(); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. //app.UseHsts(); } diff --git a/Selector/Scrobble/ScrobbleAlbumMapping.cs b/Selector/Scrobble/Mapping/ScrobbleAlbumMapping.cs similarity index 100% rename from Selector/Scrobble/ScrobbleAlbumMapping.cs rename to Selector/Scrobble/Mapping/ScrobbleAlbumMapping.cs diff --git a/Selector/Scrobble/ScrobbleArtistMapping.cs b/Selector/Scrobble/Mapping/ScrobbleArtistMapping.cs similarity index 100% rename from Selector/Scrobble/ScrobbleArtistMapping.cs rename to Selector/Scrobble/Mapping/ScrobbleArtistMapping.cs diff --git a/Selector/Scrobble/ScrobbleMapping.cs b/Selector/Scrobble/Mapping/ScrobbleMapping.cs similarity index 92% rename from Selector/Scrobble/ScrobbleMapping.cs rename to Selector/Scrobble/Mapping/ScrobbleMapping.cs index cd1ad92..4981014 100644 --- a/Selector/Scrobble/ScrobbleMapping.cs +++ b/Selector/Scrobble/Mapping/ScrobbleMapping.cs @@ -2,6 +2,7 @@ using Selector.Operations; using SpotifyAPI.Web; using System; +using System.Diagnostics; using System.Threading.Tasks; namespace Selector @@ -40,9 +41,13 @@ namespace Selector { logger.LogInformation("Mapping Last.fm {} ({}) to Spotify", Query, QueryType); + var netTime = Stopwatch.StartNew(); currentTask = searchClient.Item(new (QueryType, Query)); currentTask.ContinueWith(async t => { + netTime.Stop(); + logger.LogTrace("Network request took {:n} ms", netTime.ElapsedMilliseconds); + if (t.IsCompletedSuccessfully) { HandleResponse(t); diff --git a/Selector/Scrobble/ScrobbleTrackMapping.cs b/Selector/Scrobble/Mapping/ScrobbleTrackMapping.cs similarity index 100% rename from Selector/Scrobble/ScrobbleTrackMapping.cs rename to Selector/Scrobble/Mapping/ScrobbleTrackMapping.cs diff --git a/Selector/Scrobble/ScrobbleRequest.cs b/Selector/Scrobble/ScrobbleRequest.cs index d5f24c6..0aec88e 100644 --- a/Selector/Scrobble/ScrobbleRequest.cs +++ b/Selector/Scrobble/ScrobbleRequest.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging; using Selector.Operations; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -50,9 +51,14 @@ namespace Selector public Task Execute() { logger.LogInformation("Scrobble request #{} for {} by {} from {} to {}", pageNumber, username, pageSize, from, to); + + var netTime = Stopwatch.StartNew(); currentTask = userClient.GetRecentScrobbles(username, pagenumber: pageNumber, count: pageSize, from: from, to: to); currentTask.ContinueWith(async t => { + netTime.Stop(); + logger.LogTrace("Network request took {:n} ms", netTime.ElapsedMilliseconds); + if (t.IsCompletedSuccessfully) { var result = t.Result;