Skip to content

Commit dbbca96

Browse files
author
Andrii Bondarchuk
committed
EverestingHOFScraperHttpTriggerFunction improvements
1 parent 10ce387 commit dbbca96

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/FitSyncHub.Functions/Functions/EverestingHOFScraperHttpTriggerFunction.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Buffers;
2+
using System.Net;
23
using System.Text;
34
using System.Text.Json;
45
using System.Text.Json.Serialization;
@@ -45,7 +46,7 @@ public async Task<IActionResult> Run(
4546

4647
// do not know how HOF works, add this delta to be sure that we synced all
4748
// maybe need to increase days
48-
lastSyncedDateTime = lastSyncedDateTime.AddDays(-5);
49+
lastSyncedDateTime = lastSyncedDateTime.AddDays(-60);
4950

5051
const string BaseUrl = "https://hof.everesting.com/activities";
5152

@@ -212,7 +213,7 @@ private async Task StoreData(
212213
_logger.LogInformation("Page {CurrentPage} / {TotalPages}", GetCurrentPage(root), GetTotalPages(root));
213214
_logger.LogInformation("Activities: {ActivitiesCount}", activities.GetArrayLength());
214215

215-
var tasks = new List<Task>();
216+
var tasks = new List<Task<ResponseMessage>>();
216217
foreach (var activity in activities.EnumerateArray())
217218
{
218219
// Convert JsonElement → stream
@@ -232,8 +233,22 @@ private async Task StoreData(
232233
);
233234
}
234235

235-
// Fire all requests in parallel
236-
await Task.WhenAll(tasks);
236+
await foreach (var task in Task.WhenEach(tasks))
237+
{
238+
var result = await task;
239+
if (result.StatusCode == HttpStatusCode.OK)
240+
{
241+
_logger.LogInformation("Updated item successfully.");
242+
}
243+
else if (result.StatusCode == HttpStatusCode.Created)
244+
{
245+
_logger.LogInformation("Created item successfully.");
246+
}
247+
else
248+
{
249+
_logger.LogError("Failed to upsert item. Status code: {StatusCode}", result.StatusCode);
250+
}
251+
}
237252
}
238253

239254
private record ActivityItemProjection

0 commit comments

Comments
 (0)