Merged in fix/limit-time-to-response-for-cache-calls (pull request #1990)
fix: add timeout for redis-api calls SW-2635 Approved-by: Michael Zetterberg
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import * as Sentry from "@sentry/nextjs"
|
||||
|
||||
import { safeTry } from "@/utils/safeTry"
|
||||
|
||||
import { cacheLogger } from "../logger"
|
||||
import { API_KEY } from "./client"
|
||||
import { getCacheEndpoint } from "./endpoints"
|
||||
@@ -12,18 +14,20 @@ export async function deleteKey(key: string, opts?: { fuzzy?: boolean }) {
|
||||
endpoint.searchParams.set("fuzzy", "true")
|
||||
}
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: "DELETE",
|
||||
cache: "no-cache",
|
||||
headers: {
|
||||
"x-api-key": API_KEY,
|
||||
},
|
||||
})
|
||||
const [response, error] = await safeTry(
|
||||
fetch(endpoint, {
|
||||
method: "DELETE",
|
||||
cache: "no-cache",
|
||||
headers: {
|
||||
"x-api-key": API_KEY,
|
||||
},
|
||||
signal: AbortSignal.timeout(10_000),
|
||||
})
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status !== 404) {
|
||||
Sentry.captureMessage("Unable to DELETE cachekey", {
|
||||
level: "error",
|
||||
if (!response || !response.ok || error) {
|
||||
if (response?.status !== 404) {
|
||||
Sentry.captureException(error ?? new Error("Unable to DELETE cachekey"), {
|
||||
extra: {
|
||||
cacheKey: key,
|
||||
statusCode: response?.status,
|
||||
|
||||
@@ -17,10 +17,11 @@ export async function get<T>(key: string) {
|
||||
headers: {
|
||||
"x-api-key": API_KEY,
|
||||
},
|
||||
signal: AbortSignal.timeout(3_000),
|
||||
})
|
||||
)
|
||||
|
||||
if (!response || error || !response.ok) {
|
||||
if (!response || !response.ok || error) {
|
||||
if (response?.status === 404) {
|
||||
cacheLogger.debug(
|
||||
`Miss '${key}' took ${(performance.now() - perf).toFixed(2)}ms`
|
||||
@@ -28,11 +29,9 @@ export async function get<T>(key: string) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
Sentry.captureMessage("Unable to GET cachekey", {
|
||||
level: "error",
|
||||
Sentry.captureException(error ?? new Error("Unable to GET cachekey"), {
|
||||
extra: {
|
||||
cacheKey: key,
|
||||
errorMessage: error instanceof Error ? error.message : undefined,
|
||||
statusCode: response?.status,
|
||||
statusText: response?.statusText,
|
||||
},
|
||||
|
||||
@@ -16,15 +16,14 @@ export async function set<T>(key: string, value: T, ttl: CacheTime) {
|
||||
},
|
||||
body: JSON.stringify({ data: value, ttl: getCacheTimeInSeconds(ttl) }),
|
||||
cache: "no-cache",
|
||||
signal: AbortSignal.timeout(3_000),
|
||||
})
|
||||
)
|
||||
|
||||
if (!response || error || !response.ok) {
|
||||
Sentry.captureMessage("Unable to SET cachekey", {
|
||||
level: "error",
|
||||
if (!response || !response.ok || error) {
|
||||
Sentry.captureException(error ?? new Error("Unable to SET cachekey"), {
|
||||
extra: {
|
||||
cacheKey: key,
|
||||
errorMessage: error instanceof Error ? error.message : undefined,
|
||||
statusCode: response?.status,
|
||||
statusText: response?.statusText,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user