Skip to content

Commit 6f8da6e

Browse files
committedMar 11, 2024·
added debugging lines
1 parent 8a2f7cd commit 6f8da6e

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed
 

‎src/CocApi.Cache/CocApi.Cache.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Authors>devhl</Authors>
77
<Product />
88
<Description>Caches response from the Clash of Clans API.</Description>
9-
<Version>2.11.5</Version>
9+
<Version>2.11.6-debug</Version>
1010
<AssemblyVersion>2.0.0.0</AssemblyVersion>
1111
<FileVersion>2.0.0.0</FileVersion>
1212
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

‎src/CocApi.Cache/Services/WarService.cs

+44-2
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,20 @@ public WarService(
5353

5454
protected override async Task ExecuteScheduledTaskAsync(CancellationToken cancellationToken)
5555
{
56+
Logger.LogInformation("Executing war service");
57+
5658
SetDateVariables();
5759

60+
Logger.LogInformation("Setting variables");
61+
5862
WarServiceOptions options = Options.Value.Wars;
5963

6064
using var scope = ScopeFactory.CreateScope();
6165

6266
CacheDbContext dbContext = scope.ServiceProvider.GetRequiredService<CacheDbContext>();
6367

68+
Logger.LogInformation("Querying wars");
69+
6470
List<CachedWar> cachedWars = await dbContext.Wars
6571
.Where(w =>
6672
string.IsNullOrWhiteSpace(w.WarTag) &&
@@ -85,6 +91,8 @@ protected override async Task ExecuteScheduledTaskAsync(CancellationToken cancel
8591
tags.Add(cachedWar.OpponentTag);
8692
}
8793

94+
Logger.LogInformation("Querying clans");
95+
8896
List<CachedClan> allCachedClans = await dbContext.Clans
8997
.Where(c => tags.Contains(c.Tag))
9098
.AsNoTracking()
@@ -97,6 +105,8 @@ protected override async Task ExecuteScheduledTaskAsync(CancellationToken cancel
97105

98106
IClansApi clansApi = ApiFactory.Create<IClansApi>();
99107

108+
Logger.LogInformation("Iterating wars");
109+
100110
try
101111
{
102112
foreach (CachedWar cachedWar in cachedWars)
@@ -117,8 +127,12 @@ protected override async Task ExecuteScheduledTaskAsync(CancellationToken cancel
117127
tasks.Add(SendWarAnnouncementsAsync(cachedWar, cachedClans.Select(c => c.CurrentWar).ToArray(), cancellationToken));
118128
}
119129

130+
Logger.LogInformation("Waiting for tasks to complete");
131+
120132
await Task.WhenAll(tasks).WaitAsync(cancellationToken).ConfigureAwait(false);
121133

134+
Logger.LogInformation("Tasks are complete");
135+
122136
await dbContext.SaveChangesAsync(CancellationToken.None).ConfigureAwait(false);
123137
}
124138
finally
@@ -139,6 +153,8 @@ private async Task UpdateWarAsync(
139153
CachedClan? cachedOpponent,
140154
CancellationToken cancellationToken)
141155
{
156+
Logger.LogInformation("Creating cached clans");
157+
142158
if (cachedClan == null && cachedOpponent?.CurrentWar.IsExpired == true)
143159
cachedClan = await CreateCachedClan(clansApi, cachedWar.ClanTag, dbContext, cancellationToken).ConfigureAwait(false);
144160

@@ -158,17 +174,21 @@ private async Task UpdateWarAsync(
158174
.OrderByDescending(c => c?.CurrentWar.ExpiresAt)
159175
.FirstOrDefault(c => c?.CurrentWar.PreparationStartTime == cachedWar.PreparationStartTime);
160176

161-
if (cachedWar.Content != null &&
162-
clan?.CurrentWar.Content != null &&
177+
if (cachedWar.Content != null &&
178+
clan?.CurrentWar.Content != null &&
163179
CachedWar.HasUpdated(cachedWar, clan.CurrentWar) &&
164180
ClanWarUpdated != null)
181+
{
182+
Logger.LogInformation("sending the war updated event");
183+
165184
await ClanWarUpdated.Invoke(this, new ClanWarUpdatedEventArgs(
166185
cachedWar.Content,
167186
clan.CurrentWar.Content,
168187
cachedClan?.Content,
169188
cachedOpponent?.Content,
170189
cancellationToken))
171190
.ConfigureAwait(false);
191+
}
172192

173193
if (clan != null)
174194
{
@@ -183,6 +203,9 @@ private async Task UpdateWarAsync(
183203
c.CurrentWar.PreparationStartTime > cachedWar.PreparationStartTime
184204
)))
185205
cachedWar.IsFinal = true;
206+
207+
208+
Logger.LogInformation("Done sending war updated event");
186209
}
187210

188211
private async Task<CachedClan?> CreateCachedClan(IClansApi clansApi, string tag, CacheDbContext dbContext, CancellationToken cancellationToken)
@@ -194,6 +217,8 @@ private async Task UpdateWarAsync(
194217
{
195218
_unmonitoredClans.Add(tag);
196219

220+
Logger.LogInformation("Creating cached clan war from current war");
221+
197222
CachedClanWar cachedClanWar = await CachedClanWar
198223
.FromCurrentWarResponseAsync(tag, Options.Value.RealTime == null ? default : new(Options.Value.RealTime.Value), TimeToLiveProvider, clansApi, cancellationToken)
199224
.ConfigureAwait(false);
@@ -240,7 +265,11 @@ private async Task SendWarAnnouncementsAsync(CachedWar cachedWar, CachedClanWar[
240265
cachedWar.Announcements |= Announcements.WarStartingSoon;
241266

242267
if (ClanWarStartingSoon != null)
268+
{
269+
Logger.LogInformation("Clan war starting soon");
270+
243271
await ClanWarStartingSoon.Invoke(this, new WarEventArgs(cachedWar.Content, cancellationToken)).ConfigureAwait(false);
272+
}
244273
}
245274

246275
if (cachedWar.Announcements.HasFlag(Announcements.WarEndingSoon) == false &&
@@ -250,7 +279,10 @@ private async Task SendWarAnnouncementsAsync(CachedWar cachedWar, CachedClanWar[
250279
cachedWar.Announcements |= Announcements.WarEndingSoon;
251280

252281
if (ClanWarEndingSoon != null)
282+
{
283+
Logger.LogInformation("Clan war ending soon");
253284
await ClanWarEndingSoon.Invoke(this, new WarEventArgs(cachedWar.Content, cancellationToken)).ConfigureAwait(false);
285+
}
254286
}
255287

256288
if (cachedWar.Announcements.HasFlag(Announcements.WarEndNotSeen) == false &&
@@ -264,7 +296,11 @@ private async Task SendWarAnnouncementsAsync(CachedWar cachedWar, CachedClanWar[
264296
cachedWar.Announcements |= Announcements.WarEndNotSeen;
265297

266298
if (ClanWarEndNotSeen != null)
299+
{
300+
Logger.LogInformation("Clan war end not seen");
301+
267302
await ClanWarEndNotSeen.Invoke(this, new WarEventArgs(cachedWar.Content, cancellationToken)).ConfigureAwait(false);
303+
}
268304
}
269305

270306
if (cachedWar.Announcements.HasFlag(Announcements.WarEnded) == false &&
@@ -274,8 +310,14 @@ private async Task SendWarAnnouncementsAsync(CachedWar cachedWar, CachedClanWar[
274310
cachedWar.Announcements |= Announcements.WarEnded;
275311

276312
if (ClanWarEnded != null)
313+
{
314+
Logger.LogInformation("Clan war ended");
315+
277316
await ClanWarEnded.Invoke(this, new WarEventArgs(cachedWar.Content, cancellationToken)).ConfigureAwait(false);
317+
}
278318
}
319+
320+
Logger.LogInformation("done sending war announcement");
279321
}
280322
catch (Exception e)
281323
{

0 commit comments

Comments
 (0)
Please sign in to comment.