mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-30 09:15:19 +02:00
♻️ Adjust the polling interval to 30s for valid certs
This commit is contained in:
+16
-14
@@ -28,6 +28,8 @@ type UseCertificateReturn = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const POLL_JITTER_MS = durationToMs(1, "seconds");
|
const POLL_JITTER_MS = durationToMs(1, "seconds");
|
||||||
|
/** A valid cert isn't going anywhere soon, so check on it far less often. */
|
||||||
|
const VALID_POLL_INTERVAL_MS = durationToMs(30, "seconds");
|
||||||
|
|
||||||
export function useCertificate({
|
export function useCertificate({
|
||||||
orgId,
|
orgId,
|
||||||
@@ -35,7 +37,7 @@ export function useCertificate({
|
|||||||
fullDomain,
|
fullDomain,
|
||||||
initialCertValue,
|
initialCertValue,
|
||||||
polling = false,
|
polling = false,
|
||||||
pollingInterval = 5000
|
pollingInterval = durationToMs(5, "seconds")
|
||||||
}: UseCertificateProps): UseCertificateReturn {
|
}: UseCertificateProps): UseCertificateReturn {
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@@ -49,19 +51,19 @@ export function useCertificate({
|
|||||||
const { data, isLoading, isError, refetch } = useQuery({
|
const { data, isLoading, isError, refetch } = useQuery({
|
||||||
...certQuery,
|
...certQuery,
|
||||||
enabled: Boolean(orgId && domainId && fullDomain),
|
enabled: Boolean(orgId && domainId && fullDomain),
|
||||||
// Add a small random offset to each tick. Without it, every row in a
|
refetchInterval: (query) => {
|
||||||
// table would poll at the exact same instant, hitting the server in
|
if (!polling) return false;
|
||||||
// bursts instead of spreading the requests out.
|
const interval =
|
||||||
refetchInterval: polling
|
query.state.data?.status === "valid"
|
||||||
? () =>
|
? VALID_POLL_INTERVAL_MS
|
||||||
Math.max(
|
: pollingInterval;
|
||||||
1000,
|
// Add a small random offset to each tick. Without it, every row in
|
||||||
Math.round(
|
// a table would poll at the exact same instant, hitting the server
|
||||||
pollingInterval +
|
// in bursts instead of spreading the requests out.
|
||||||
(Math.random() * 2 - 1) * POLL_JITTER_MS
|
// the requests will be jittered by less or more than 1s
|
||||||
)
|
const jitter = (Math.random() * 2 - 1) * POLL_JITTER_MS;
|
||||||
)
|
return Math.max(1000, interval + jitter);
|
||||||
: false,
|
},
|
||||||
// An explicit `null` is a real answer ("this domain has no certificate")
|
// An explicit `null` is a real answer ("this domain has no certificate")
|
||||||
// and is seeded like any other, so a server-prefetched row doesn't
|
// and is seeded like any other, so a server-prefetched row doesn't
|
||||||
// refetch on mount. Only an omitted prop leaves the cache empty.
|
// refetch on mount. Only an omitted prop leaves the cache empty.
|
||||||
|
|||||||
Reference in New Issue
Block a user