Looks like we finally have a solution.
Change logging to just log a message, instead of the exception. Moved logic to Syncer involvement. When posting the data, if a 500 is returned, then it is up to the Syncer to re-submit it.
This commit is contained in:
parent
73955353cb
commit
004c490dd8
23 changed files with 529 additions and 177 deletions
|
|
@ -32,25 +32,22 @@ public static class HistoryEndpoint
|
|||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("History {id} does not exist, adding it to the database Thread: {thread}",
|
||||
history._id, Thread.CurrentThread.ManagedThreadId);
|
||||
await repository.AddAsync(history, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create history {json}", history._id);
|
||||
logger.LogError("Failed to create history {json}", history._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
await repository.UpdateAsync(history, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to update history {json}", history._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
logger.LogInformation("History {id} exists, updating the database. Thread: {thread}", history._id,
|
||||
Thread.CurrentThread.ManagedThreadId);
|
||||
results.UpdateFrom(history);
|
||||
await repository.UpdateAsync(results, ct);
|
||||
}
|
||||
return Results.Ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ public static class PingEndpoint
|
|||
public static void MapPingEndpoints(this WebApplication app)
|
||||
{
|
||||
var group = app.MapGroup("ping");
|
||||
group.MapGet("/", async (CancellationToken token) =>
|
||||
group.MapGet("/", async (DataContext dbContext, CancellationToken token) =>
|
||||
{
|
||||
await Task.Delay(10);
|
||||
var dict = new { AppVersion = "0.1.4" };
|
||||
await dbContext.CleanupChangeLogAsync(token);
|
||||
var dict = new { AppVersion = "0.1.5" };
|
||||
return Results.Ok(dict);
|
||||
});
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ public static class PingEndpoint
|
|||
return Results.NotFound();
|
||||
|
||||
var dict = new { LastUpdated = log.ChangeTime };
|
||||
await dbContext.CleanupChangeLogAsync(token);
|
||||
return Results.Ok(dict);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,24 +34,21 @@ public static class PlaylistEndpoint
|
|||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("Playlist {id} does not exist, adding it to the database", playlist._id);
|
||||
await repository.AddAsync(playlist, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create Playlist {playlist}", playlist._id);
|
||||
logger.LogError("Failed to create Playlist {playlist}", playlist._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add Update Code here
|
||||
logger.LogInformation("Playlist {id} exists, updating the databsae.", playlist._id);
|
||||
results.UpdateFrom(playlist);
|
||||
var toRemove = results.videos.Where(vid => !playlist.videos.Any(x => x.playlistItemId == vid.playlistItemId)).ToList();
|
||||
|
||||
results.lastUpdatedAt = playlist.lastUpdatedAt;
|
||||
results.@protected = playlist.@protected;
|
||||
results.playlistName = playlist.playlistName;
|
||||
results.createdAt = playlist.createdAt;
|
||||
|
||||
foreach (var vid in toRemove)
|
||||
results.videos.Remove(vid);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,22 +33,21 @@ public static class ProfileEndpoint
|
|||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("Profile {id} does not exist, adding it to the database", profile._id);
|
||||
await repository.AddAsync(profile, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create profile {json}", profile._id);
|
||||
logger.LogError("Failed to create profile {json}", profile._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("Profile {id} exists, updating the database.", profile._id);
|
||||
res.UpdateFrom(profile);
|
||||
var toRemove = res.subscriptions.Where(sub => !profile.subscriptions.Any(x => x.id == sub.id)).ToList();
|
||||
|
||||
res.name = profile.name;
|
||||
res.textColor = profile.textColor;
|
||||
res.bgColor = profile.bgColor;
|
||||
|
||||
foreach (var sub in toRemove)
|
||||
res.subscriptions.Remove(sub);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,25 +34,20 @@ public static class SearchHistoryEndpoint
|
|||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("SearchHistory {id} does not exist, adding it to the database", history._id);
|
||||
await repository.AddAsync(history, ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
logger.LogError(e, "Failed to update history {json}", history._id);
|
||||
logger.LogError("Failed to update history {json}", history._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
await repository.UpdateAsync(history, ct);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Failed to update history {json}", history._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
logger.LogInformation("SearchHistory {id} exists, updating the database.", history._id);
|
||||
result.UpdateFrom(history);
|
||||
await repository.UpdateAsync(result, ct);
|
||||
}
|
||||
|
||||
return Results.Ok();
|
||||
|
|
|
|||
|
|
@ -33,25 +33,20 @@ public static class SettingEndpoint
|
|||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("Setting {id} does not exist, adding it to the database", setting._id);
|
||||
await repository.AddAsync(setting, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
logger.LogError(ex, "Failed to add setting {setting}", setting._id);
|
||||
logger.LogError("Failed to add setting {setting}", setting._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
await repository.UpdateAsync(setting, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to update setting {setting}", setting._id);
|
||||
return Results.StatusCode(500);
|
||||
}
|
||||
logger.LogInformation("Setting {id} exists, updating the database.", setting._id);
|
||||
res.UpdateFrom(setting);
|
||||
await repository.UpdateAsync(res, ct);
|
||||
}
|
||||
return Results.Ok();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue