diff --git a/src/CocApi.Cache/CocApi.Cache.csproj b/src/CocApi.Cache/CocApi.Cache.csproj
index dd339b6..8c3bb6d 100644
--- a/src/CocApi.Cache/CocApi.Cache.csproj
+++ b/src/CocApi.Cache/CocApi.Cache.csproj
@@ -6,7 +6,7 @@
devhl
Caches response from the Clash of Clans API.
- 2.11.9
+ 2.11.10
2.0.0.0
2.0.0.0
true
diff --git a/src/CocApi.Cache/Services/WarService.cs b/src/CocApi.Cache/Services/WarService.cs
index 51b9b57..5386098 100644
--- a/src/CocApi.Cache/Services/WarService.cs
+++ b/src/CocApi.Cache/Services/WarService.cs
@@ -139,50 +139,60 @@ private async Task UpdateWarAsync(
CachedClan? cachedOpponent,
CancellationToken cancellationToken)
{
- if (cachedClan == null && cachedOpponent?.CurrentWar.IsExpired == true)
- cachedClan = await CreateCachedClan(clansApi, cachedWar.ClanTag, dbContext, cancellationToken).ConfigureAwait(false);
+ try
+ {
+ if (cachedClan == null && cachedOpponent?.CurrentWar.IsExpired == true)
+ cachedClan = await CreateCachedClan(clansApi, cachedWar.ClanTag, dbContext, cancellationToken).ConfigureAwait(false);
- if (cachedOpponent == null && cachedClan?.CurrentWar.IsExpired == true)
- cachedOpponent = await CreateCachedClan(clansApi, cachedWar.OpponentTag, dbContext, cancellationToken).ConfigureAwait(false);
+ if (cachedOpponent == null && cachedClan?.CurrentWar.IsExpired == true)
+ cachedOpponent = await CreateCachedClan(clansApi, cachedWar.OpponentTag, dbContext, cancellationToken).ConfigureAwait(false);
- List cachedClans = new() { cachedClan, cachedOpponent };
+ List cachedClans = new() { cachedClan, cachedOpponent };
- if (cachedClans.All(c => c?.CurrentWar.PreparationStartTime > cachedWar.PreparationStartTime) || cachedWar.EndTime.AddDays(8) < now)
- {
- cachedWar.IsFinal = true;
+ if (cachedClans.All(c => c?.CurrentWar.PreparationStartTime > cachedWar.PreparationStartTime) || cachedWar.EndTime.AddDays(8) < now)
+ {
+ cachedWar.IsFinal = true;
- return;
- }
+ return;
+ }
- CachedClan? clan = cachedClans
- .OrderByDescending(c => c?.CurrentWar.ExpiresAt)
- .FirstOrDefault(c => c?.CurrentWar.PreparationStartTime == cachedWar.PreparationStartTime);
-
- if (cachedWar.Content != null &&
- clan?.CurrentWar.Content != null &&
- CachedWar.HasUpdated(cachedWar, clan.CurrentWar) &&
- ClanWarUpdated != null)
- await ClanWarUpdated.Invoke(this, new ClanWarUpdatedEventArgs(
- cachedWar.Content,
- clan.CurrentWar.Content,
- cachedClan?.Content,
- cachedOpponent?.Content,
- cancellationToken))
- .ConfigureAwait(false);
+ CachedClan? clan = cachedClans
+ .OrderByDescending(c => c?.CurrentWar.ExpiresAt)
+ .FirstOrDefault(c => c?.CurrentWar.PreparationStartTime == cachedWar.PreparationStartTime);
+
+ if (cachedWar.Content != null &&
+ clan?.CurrentWar.Content != null &&
+ CachedWar.HasUpdated(cachedWar, clan.CurrentWar) &&
+ ClanWarUpdated != null)
+ await ClanWarUpdated.Invoke(this, new ClanWarUpdatedEventArgs(
+ cachedWar.Content,
+ clan.CurrentWar.Content,
+ cachedClan?.Content,
+ cachedOpponent?.Content,
+ cancellationToken))
+ .ConfigureAwait(false);
+
+ if (clan != null)
+ {
+ cachedWar.UpdateFrom(clan.CurrentWar);
- if (clan != null)
+ cachedWar.IsFinal = clan.CurrentWar.State == Rest.Models.WarState.WarEnded;
+ }
+ else if (cachedClans.All(c =>
+ c != null &&
+ (
+ c.CurrentWar.PreparationStartTime == DateTime.MinValue ||
+ c.CurrentWar.PreparationStartTime > cachedWar.PreparationStartTime
+ )))
+ cachedWar.IsFinal = true;
+ }
+ catch (Exception e)
{
- cachedWar.UpdateFrom(clan.CurrentWar);
- cachedWar.IsFinal = clan.CurrentWar.State == Rest.Models.WarState.WarEnded;
+ Logger.LogError(e, "UpdateWarAsync war: {} clan: {}", cachedWar.PreparationStartTime, cachedClan?.Tag ?? cachedOpponent?.Tag);
+
+ throw;
}
- else if (cachedClans.All(c =>
- c != null &&
- (
- c.CurrentWar.PreparationStartTime == DateTime.MinValue ||
- c.CurrentWar.PreparationStartTime > cachedWar.PreparationStartTime
- )))
- cachedWar.IsFinal = true;
}
private async Task CreateCachedClan(IClansApi clansApi, string tag, CacheDbContext dbContext, CancellationToken cancellationToken)
@@ -220,6 +230,12 @@ private async Task UpdateWarAsync(
return cachedClan;
}
+ catch(Exception e)
+ {
+ Logger.LogError(e, "CreateCachedClan: {tag}", tag);
+
+ throw;
+ }
finally
{
Synchronizer.UpdatingClan.TryRemove(tag, out _);