Smoke-test /health for the reachable (200) and unreachable (503) cases
This commit is contained in:
1 parent
c67c71ea28
commit
666614a3b2
4 files changed
+110
-28
No files matched your search
@@ -108,6 +108,43 @@ public sealed class PocketBaseClient(HttpClient httpClient)
|
||||
public Task<IReadOnlyList<FaqTopic>> GetFaqTopicsAsync(CancellationToken token = default)
|
||||
=> GetRecordsAsync<FaqTopic>("faq_topics", "order", token, expand: "faqs_via_topic");
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether PocketBase answers its health endpoint.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Backs the app's own <c>/health</c> endpoint, which an external monitor (Uptime
|
||||
/// Kuma) polls: the app answering at all proves the app is up, and this probe adds
|
||||
/// whether the content source behind it is reachable, so one monitor covers both.
|
||||
/// This calls <c>GET /api/health</c>, PocketBase's own liveness endpoint, which
|
||||
/// needs no auth and touches no collection.
|
||||
/// </remarks>
|
||||
/// <param name="token">
|
||||
/// A token to cancel the probe.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if PocketBase answered with a success status within the
|
||||
/// client timeout; <see langword="false"/> if it was unreachable, timed out, or
|
||||
/// answered with an error status.
|
||||
/// </returns>
|
||||
public async Task<bool> IsHealthyAsync(CancellationToken token = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var response = await httpClient.GetAsync(
|
||||
new Uri("/api/health", UriKind.Relative), token);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
// Same failure shapes as a record read: unreachable (HttpRequestException) or the
|
||||
// client's own timeout (a TaskCanceledException wrapping a TimeoutException). A
|
||||
// plain TaskCanceledException is the caller's cancellation and propagates.
|
||||
catch (Exception exception) when (
|
||||
exception is HttpRequestException
|
||||
or TaskCanceledException { InnerException: TimeoutException })
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all public records of a collection in a single request.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user