fixing tests and warnings

This commit is contained in:
andy 2022-02-25 18:32:43 +00:00
parent d6e720ed72
commit 18afeb131b
8 changed files with 20 additions and 18 deletions

View File

@ -40,7 +40,7 @@ namespace Selector.CLI.Services
await RunScrobbleSavers(db, cancellationToken); await RunScrobbleSavers(db, cancellationToken);
} }
public async Task RunScrobbleSavers(ApplicationDbContext db, CancellationToken token) public Task RunScrobbleSavers(ApplicationDbContext db, CancellationToken token)
{ {
using var scope = serviceScopeFactory.CreateScope(); using var scope = serviceScopeFactory.CreateScope();
@ -51,6 +51,8 @@ namespace Selector.CLI.Services
{ {
//TODO //TODO
} }
return Task.CompletedTask;
} }
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)

View File

@ -25,13 +25,13 @@ namespace Selector.Cache
LoggerFactory = loggerFactory; LoggerFactory = loggerFactory;
} }
public async Task<IConsumer> Get(IPlayerWatcher watcher = null) public Task<IConsumer> Get(IPlayerWatcher watcher = null)
{ {
return new CacheWriter( return Task.FromResult<IConsumer>(new CacheWriter(
watcher, watcher,
Cache, Cache,
LoggerFactory.CreateLogger<CacheWriter>() LoggerFactory.CreateLogger<CacheWriter>()
); ));
} }
} }
} }

View File

@ -28,7 +28,7 @@ namespace Selector.Cache
Creds = creds; Creds = creds;
} }
public async Task<IConsumer> Get(LastfmClient fmClient = null, LastFmCredentials creds = null, IPlayerWatcher watcher = null) public Task<IConsumer> Get(LastfmClient fmClient = null, LastFmCredentials creds = null, IPlayerWatcher watcher = null)
{ {
var client = fmClient ?? Client; var client = fmClient ?? Client;
@ -37,7 +37,7 @@ namespace Selector.Cache
throw new ArgumentNullException("No Last.fm client provided"); throw new ArgumentNullException("No Last.fm client provided");
} }
return new PlayCounterCaching( return Task.FromResult<IConsumer>(new PlayCounterCaching(
watcher, watcher,
client.Track, client.Track,
client.Album, client.Album,
@ -46,7 +46,7 @@ namespace Selector.Cache
Cache, Cache,
credentials: creds ?? Creds, credentials: creds ?? Creds,
logger: LoggerFactory.CreateLogger<PlayCounterCaching>() logger: LoggerFactory.CreateLogger<PlayCounterCaching>()
); ));
} }
} }
} }

View File

@ -25,13 +25,13 @@ namespace Selector.Cache
LoggerFactory = loggerFactory; LoggerFactory = loggerFactory;
} }
public async Task<IConsumer> Get(IPlayerWatcher watcher = null) public Task<IConsumer> Get(IPlayerWatcher watcher = null)
{ {
return new Publisher( return Task.FromResult<IConsumer>(new Publisher(
watcher, watcher,
Subscriber, Subscriber,
LoggerFactory.CreateLogger<Publisher>() LoggerFactory.CreateLogger<Publisher>()
); ));
} }
} }
} }

View File

@ -26,7 +26,7 @@ namespace Selector
Creds = creds; Creds = creds;
} }
public async Task<IConsumer> Get(LastfmClient fmClient = null, LastFmCredentials creds = null, IPlayerWatcher watcher = null) public Task<IConsumer> Get(LastfmClient fmClient = null, LastFmCredentials creds = null, IPlayerWatcher watcher = null)
{ {
var client = fmClient ?? Client; var client = fmClient ?? Client;
@ -35,7 +35,7 @@ namespace Selector
throw new ArgumentNullException("No Last.fm client provided"); throw new ArgumentNullException("No Last.fm client provided");
} }
return new PlayCounter( return Task.FromResult<IConsumer>(new PlayCounter(
watcher, watcher,
client.Track, client.Track,
client.Album, client.Album,
@ -43,7 +43,7 @@ namespace Selector
client.User, client.User,
credentials: creds ?? Creds, credentials: creds ?? Creds,
LoggerFactory.CreateLogger<PlayCounter>() LoggerFactory.CreateLogger<PlayCounter>()
); ));
} }
} }
} }

View File

@ -54,8 +54,8 @@ namespace Selector
if(t.Exception.InnerException is APITooManyRequestsException ex) if(t.Exception.InnerException is APITooManyRequestsException ex)
{ {
logger.LogError("Spotify search request too many requests, waiting for {}", ex.RetryAfter); logger.LogError("Spotify search request too many requests, waiting for {}", ex.RetryAfter);
await Task.Delay(ex.RetryAfter); await Task.Delay(ex.RetryAfter.Add(TimeSpan.FromSeconds(1)));
Execute(); await Execute();
} }
else else
{ {

View File

@ -51,7 +51,7 @@ namespace Selector
{ {
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);
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(t => currentTask.ContinueWith(async t =>
{ {
if (t.IsCompletedSuccessfully) if (t.IsCompletedSuccessfully)
{ {
@ -70,7 +70,7 @@ namespace Selector
if(Attempts < MaxAttempts) if(Attempts < MaxAttempts)
{ {
logger.LogDebug("Request failed for {}, #{} by {}: {}, retrying ({} of {})", username, pageNumber, pageSize, result.Status, Attempts + 1, MaxAttempts); logger.LogDebug("Request failed for {}, #{} by {}: {}, retrying ({} of {})", username, pageNumber, pageSize, result.Status, Attempts + 1, MaxAttempts);
Execute(); await Execute();
} }
else else
{ {

View File

@ -40,7 +40,7 @@ namespace Selector
public IWatcherContext Add(IWatcher watcher) public IWatcherContext Add(IWatcher watcher)
{ {
return Add(watcher, default); return Add(watcher, Enumerable.Empty<IConsumer>());
} }
public IWatcherContext Add(IWatcher watcher, IEnumerable<IConsumer> consumers) public IWatcherContext Add(IWatcher watcher, IEnumerable<IConsumer> consumers)