fixed cron schedule again, error handling scrobble

scrobble request and mapping
This commit is contained in:
andy 2022-03-03 17:38:49 +00:00
parent 349d62b5cc
commit 12842c240b
3 changed files with 55 additions and 39 deletions

View File

@ -124,7 +124,7 @@ namespace Selector.CLI
public const string Key = "Scrobble";
public bool Enabled { get; set; } = true;
public string FullScrobbleCron { get; set; } = "0 0 2 * * *";
public string FullScrobbleCron { get; set; } = "0 0 2 * * ?";
public TimeSpan InterJobDelay { get; set; } = TimeSpan.FromMinutes(5);
public TimeSpan InterRequestDelay { get; set; } = TimeSpan.FromMilliseconds(100);
public DateTime? From { get; set; } = DateTime.UtcNow.AddDays(-14);

View File

@ -44,6 +44,8 @@ namespace Selector
var netTime = Stopwatch.StartNew();
currentTask = searchClient.Item(new (QueryType, Query));
currentTask.ContinueWith(async t =>
{
try
{
netTime.Stop();
logger.LogTrace("Network request took {:n} ms", netTime.ElapsedMilliseconds);
@ -56,7 +58,7 @@ namespace Selector
}
else
{
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);
await Task.Delay(ex.RetryAfter.Add(TimeSpan.FromSeconds(1)));
@ -68,6 +70,12 @@ namespace Selector
AggregateTaskSource.SetException(t.Exception);
}
}
}
catch (Exception e)
{
logger.LogError(e, "Error while mapping Last.fm {} ({}) to Spotify on attempt {}", Query, QueryType, Attempts);
Succeeded = false;
}
});
Attempts++;

View File

@ -55,6 +55,8 @@ namespace Selector
var netTime = Stopwatch.StartNew();
currentTask = userClient.GetRecentScrobbles(username, pagenumber: pageNumber, count: pageSize, from: from, to: to);
currentTask.ContinueWith(async t =>
{
try
{
netTime.Stop();
logger.LogTrace("Network request took {:n} ms", netTime.ElapsedMilliseconds);
@ -73,7 +75,7 @@ namespace Selector
}
else
{
if(Attempts < MaxAttempts)
if (Attempts < MaxAttempts)
{
logger.LogDebug("Request failed for {}, #{} by {}: {}, retrying ({} of {})", username, pageNumber, pageSize, result.Status, Attempts + 1, MaxAttempts);
await Execute();
@ -90,6 +92,12 @@ namespace Selector
logger.LogError("Scrobble request task faulted, {}", t.Exception);
AggregateTaskSource.SetException(t.Exception);
}
}
catch(Exception e)
{
logger.LogError(e, "Error while making scrobble request #{} for {} by {} from {} to {} on attempt {}", pageNumber, username, pageSize, from, to, Attempts);
Succeeded = false;
}
});
Attempts++;