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

View File

@ -25,13 +25,13 @@ namespace Selector.Cache
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,
Cache,
LoggerFactory.CreateLogger<CacheWriter>()
);
));
}
}
}

View File

@ -28,7 +28,7 @@ namespace Selector.Cache
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;
@ -37,7 +37,7 @@ namespace Selector.Cache
throw new ArgumentNullException("No Last.fm client provided");
}
return new PlayCounterCaching(
return Task.FromResult<IConsumer>(new PlayCounterCaching(
watcher,
client.Track,
client.Album,
@ -46,7 +46,7 @@ namespace Selector.Cache
Cache,
credentials: creds ?? Creds,
logger: LoggerFactory.CreateLogger<PlayCounterCaching>()
);
));
}
}
}

View File

@ -25,13 +25,13 @@ namespace Selector.Cache
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,
Subscriber,
LoggerFactory.CreateLogger<Publisher>()
);
));
}
}
}

View File

@ -26,7 +26,7 @@ namespace Selector
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;
@ -35,7 +35,7 @@ namespace Selector
throw new ArgumentNullException("No Last.fm client provided");
}
return new PlayCounter(
return Task.FromResult<IConsumer>(new PlayCounter(
watcher,
client.Track,
client.Album,
@ -43,7 +43,7 @@ namespace Selector
client.User,
credentials: creds ?? Creds,
LoggerFactory.CreateLogger<PlayCounter>()
);
));
}
}
}

View File

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

View File

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

View File

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