added job parallel lock, file structure, diagnostics

This commit is contained in:
andy 2022-02-25 23:58:01 +00:00
parent bf55f7222e
commit 35c24ad0ef
7 changed files with 13 additions and 1 deletions

View File

@ -12,6 +12,7 @@ using System.Threading.Tasks;
namespace Selector.CLI.Jobs namespace Selector.CLI.Jobs
{ {
[DisallowConcurrentExecution]
public class ScrobbleWatcherJob : IJob public class ScrobbleWatcherJob : IJob
{ {
private readonly ILogger<ScrobbleWatcherJob> logger; private readonly ILogger<ScrobbleWatcherJob> logger;

View File

@ -125,11 +125,11 @@ namespace Selector.Web
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseHttpsRedirection();
} }
else else
{ {
app.UseExceptionHandler("/Error"); 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. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
//app.UseHsts(); //app.UseHsts();
} }

View File

@ -2,6 +2,7 @@
using Selector.Operations; using Selector.Operations;
using SpotifyAPI.Web; using SpotifyAPI.Web;
using System; using System;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Selector namespace Selector
@ -40,9 +41,13 @@ namespace Selector
{ {
logger.LogInformation("Mapping Last.fm {} ({}) to Spotify", Query, QueryType); logger.LogInformation("Mapping Last.fm {} ({}) to Spotify", Query, QueryType);
var netTime = Stopwatch.StartNew();
currentTask = searchClient.Item(new (QueryType, Query)); currentTask = searchClient.Item(new (QueryType, Query));
currentTask.ContinueWith(async t => currentTask.ContinueWith(async t =>
{ {
netTime.Stop();
logger.LogTrace("Network request took {:n} ms", netTime.ElapsedMilliseconds);
if (t.IsCompletedSuccessfully) if (t.IsCompletedSuccessfully)
{ {
HandleResponse(t); HandleResponse(t);

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using Selector.Operations; using Selector.Operations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -50,9 +51,14 @@ namespace Selector
public Task Execute() public Task Execute()
{ {
logger.LogInformation("Scrobble request #{} for {} by {} from {} to {}", pageNumber, username, pageSize, from, to); 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 = userClient.GetRecentScrobbles(username, pagenumber: pageNumber, count: pageSize, from: from, to: to);
currentTask.ContinueWith(async t => currentTask.ContinueWith(async t =>
{ {
netTime.Stop();
logger.LogTrace("Network request took {:n} ms", netTime.ElapsedMilliseconds);
if (t.IsCompletedSuccessfully) if (t.IsCompletedSuccessfully)
{ {
var result = t.Result; var result = t.Result;