fix: handle Convex InvalidCursor and align backend config
This commit is contained in:
parent
3565500e9c
commit
07a6f101b8
6 changed files with 44 additions and 9 deletions
4
bun.lock
4
bun.lock
|
|
@ -41,7 +41,7 @@
|
||||||
"better-auth": "^1.3.26",
|
"better-auth": "^1.3.26",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"convex": "^1.28.0",
|
"convex": "^1.29.2",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"lucide-react": "^0.544.0",
|
"lucide-react": "^0.544.0",
|
||||||
|
|
@ -1026,7 +1026,7 @@
|
||||||
|
|
||||||
"convert-source-map": ["convert-source-map@2.0.0", "", {}, "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="],
|
"convert-source-map": ["convert-source-map@2.0.0", "", {}, "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="],
|
||||||
|
|
||||||
"convex": ["convex@1.28.0", "", { "dependencies": { "esbuild": "0.25.4", "prettier": "3.6.2" }, "optionalDependencies": { "react": "19.2.0" }, "bin": { "convex": "bin/main.js" } }, "sha512-40FgeJ/LxP9TxnkDDztU/A5gcGTdq1klcTT5mM0Ak+kSlQiDktMpjNX1TfkWLxXaE3lI4qvawKH95v2RiYgFxA=="],
|
"convex": ["convex@1.29.2", "", { "dependencies": { "esbuild": "0.25.4", "prettier": "^3.0.0" }, "peerDependencies": { "@auth0/auth0-react": "^2.0.1", "@clerk/clerk-react": "^4.12.8 || ^5.0.0", "react": "^18.0.0 || ^19.0.0-0 || ^19.0.0" }, "optionalPeers": ["@auth0/auth0-react", "@clerk/clerk-react", "react"], "bin": { "convex": "bin/main.js" } }, "sha512-9QCj53/zFV+hHZRP8epU41a3NmOkYDdEtpvSPKjAZp6l60NMN+O3fyOX4r5Y6yzPIhsUpJvMH6xB5xwJTLz92A=="],
|
||||||
|
|
||||||
"crelt": ["crelt@1.0.6", "", {}, "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g=="],
|
"crelt": ["crelt@1.0.6", "", {}, "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g=="],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,39 @@ async function paginateTickets<T>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const page: PaginatedResult<T> = await paginateFn.call(query, { cursor, numItems: pageSize });
|
let page: PaginatedResult<T>;
|
||||||
|
try {
|
||||||
|
page = await paginateFn.call(query, { cursor, numItems: pageSize });
|
||||||
|
} catch (error) {
|
||||||
|
// Em cenários raros o Convex pode lançar InvalidCursor quando
|
||||||
|
// o fingerprint da query muda entre páginas. Nesse caso,
|
||||||
|
// fazemos fallback para uma leitura simples via collect()
|
||||||
|
// para evitar quebrar o dashboard.
|
||||||
|
const message = (error as Error | null | undefined)?.message ?? "";
|
||||||
|
const isInvalidCursor =
|
||||||
|
typeof message === "string" &&
|
||||||
|
message.includes("InvalidCursor");
|
||||||
|
// Alguns erros de paginação vêm embrulhados em ConvexError com metadados.
|
||||||
|
const data = (error as any)?.data;
|
||||||
|
const isPaginationInvalidCursor =
|
||||||
|
data && typeof data === "object" && data.paginationError === "InvalidCursor";
|
||||||
|
|
||||||
|
if (isInvalidCursor || isPaginationInvalidCursor) {
|
||||||
|
const fallbackQuery = buildQuery();
|
||||||
|
const collectFn = fallbackQuery.collect;
|
||||||
|
if (typeof collectFn !== "function") {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
const docs = await collectFn.call(fallbackQuery);
|
||||||
|
for (const doc of docs) {
|
||||||
|
await handler(doc);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
for (const doc of page.page) {
|
for (const doc of page.page) {
|
||||||
await handler(doc);
|
await handler(doc);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ const nextConfig = {
|
||||||
experimental: {
|
experimental: {
|
||||||
turbopackFileSystemCacheForDev: true,
|
turbopackFileSystemCacheForDev: true,
|
||||||
},
|
},
|
||||||
|
// Não há necessidade de alterar o webpack aqui; o código do backend Convex
|
||||||
|
// (convex-backend-main) não faz parte do bundle Next.
|
||||||
}
|
}
|
||||||
|
|
||||||
export default nextConfig
|
export default nextConfig
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
"better-auth": "^1.3.26",
|
"better-auth": "^1.3.26",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"convex": "^1.28.0",
|
"convex": "^1.29.2",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"lucide-react": "^0.544.0",
|
"lucide-react": "^0.544.0",
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ services:
|
||||||
start_period: 30s
|
start_period: 30s
|
||||||
|
|
||||||
convex_backend:
|
convex_backend:
|
||||||
image: ghcr.io/get-convex/convex-backend:latest
|
image: sistema_convex_backend:1.29.2
|
||||||
stop_grace_period: 10s
|
stop_grace_period: 10s
|
||||||
stop_signal: SIGINT
|
stop_signal: SIGINT
|
||||||
volumes:
|
volumes:
|
||||||
|
|
@ -90,10 +90,10 @@ services:
|
||||||
failure_action: rollback
|
failure_action: rollback
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
# Limite conservador para evitar que o backend afete o host inteiro.
|
# Limite de memória elevado para evitar reinícios por OOM (exit code 137) em cargas de relatórios / índices.
|
||||||
memory: "12G"
|
memory: "16G"
|
||||||
reservations:
|
reservations:
|
||||||
memory: "3G"
|
memory: "4G"
|
||||||
restart_policy:
|
restart_policy:
|
||||||
condition: any
|
condition: any
|
||||||
placement:
|
placement:
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"apps/desktop/**",
|
"apps/desktop/**",
|
||||||
"nova-calendar-main/**"
|
"nova-calendar-main/**",
|
||||||
|
"convex-backend-main/**"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue