forked from kc3hack/2024_H
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
Epub/KoeBook.Epub/Contracts/Services/IScrapingClientService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace KoeBook.Epub.Contracts.Services; | ||
|
||
public interface IScrapingClientService | ||
{ | ||
/// <summary> | ||
/// スクレイピングでGETする用 | ||
/// APIは不要 | ||
/// </summary> | ||
ValueTask<HttpResponseMessage> GetAsync(string url, CancellationToken ct); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using KoeBook.Epub.Contracts.Services; | ||
|
||
namespace KoeBook.Epub.Services; | ||
|
||
public sealed class ScrapingClientService(IHttpClientFactory httpClientFactory, TimeProvider timeProvider) : IScrapingClientService, IDisposable | ||
{ | ||
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory; | ||
private readonly PeriodicTimer _periodicTimer = new(TimeSpan.FromSeconds(10), timeProvider); | ||
|
||
public void Dispose() | ||
{ | ||
_periodicTimer.Dispose(); | ||
} | ||
|
||
public async ValueTask<HttpResponseMessage> GetAsync(string url, CancellationToken ct) | ||
{ | ||
await _periodicTimer.WaitForNextTickAsync(ct).ConfigureAwait(false); | ||
|
||
var httpClient = _httpClientFactory.CreateClient(); | ||
return await httpClient.GetAsync(url, ct).ConfigureAwait(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters