From 38e1488c8cfd2cc7117726e5f9486376a7874718 Mon Sep 17 00:00:00 2001 From: Guillermo Arrieta Medina Date: Thu, 19 Feb 2026 13:06:34 -0600 Subject: [PATCH] =?UTF-8?q?Se=20a=C3=B1ade=20un=20event=20listener=20que?= =?UTF-8?q?=20loggea=20cuando=20se=20va=20a=20apagar=20la=20funci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supabase/functions/ai-generate-plan/index.ts | 7 +++++++ supabase/functions/ai-generate-subject/index.ts | 7 +++++++ supabase/functions/create-chat-conversation/index.ts | 7 +++++++ supabase/functions/generate-subject-suggestions/index.ts | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/supabase/functions/ai-generate-plan/index.ts b/supabase/functions/ai-generate-plan/index.ts index f370b75..f98a22e 100644 --- a/supabase/functions/ai-generate-plan/index.ts +++ b/supabase/functions/ai-generate-plan/index.ts @@ -19,6 +19,13 @@ type NivelType = type TipoCicloType = Database["public"]["Tables"]["planes_estudio"]["Insert"]["tipo_ciclo"]; +addEventListener("beforeunload", (ev: any) => { + // ev.detail.reason te dirá si es "timeout", "memory_limit" o "idle" + console.error("ALERTA: La función se va a apagar. Razón:", ev.detail?.reason); + + // Aquí puedes intentar un último log antes de que todo muera +}); + Deno.serve(async (req: Request): Promise => { const url = new URL(req.url); const functionName = url.pathname.split("/").pop(); diff --git a/supabase/functions/ai-generate-subject/index.ts b/supabase/functions/ai-generate-subject/index.ts index a2f5818..175cb58 100644 --- a/supabase/functions/ai-generate-subject/index.ts +++ b/supabase/functions/ai-generate-subject/index.ts @@ -9,6 +9,13 @@ import { type StructuredResponseOptions, } from "../_shared/openai-service.ts"; +addEventListener("beforeunload", (ev: any) => { + console.error( + "ALERTA: La función se va a apagar. Razón:", + ev?.detail?.reason, + ); +}); + /** * JSON input signature (when `Content-Type: application/json`) * diff --git a/supabase/functions/create-chat-conversation/index.ts b/supabase/functions/create-chat-conversation/index.ts index f06bc58..6057960 100644 --- a/supabase/functions/create-chat-conversation/index.ts +++ b/supabase/functions/create-chat-conversation/index.ts @@ -22,6 +22,13 @@ type AddMessageBody = { const app = new Hono(); +addEventListener("beforeunload", (ev: any) => { + console.error( + "ALERTA: La función se va a apagar. Razón:", + ev?.detail?.reason, + ); +}); + // Preflight CORS app.options( "*", diff --git a/supabase/functions/generate-subject-suggestions/index.ts b/supabase/functions/generate-subject-suggestions/index.ts index a6f1eb5..bb17975 100644 --- a/supabase/functions/generate-subject-suggestions/index.ts +++ b/supabase/functions/generate-subject-suggestions/index.ts @@ -10,6 +10,13 @@ import { type StructuredResponseOptions, } from "../_shared/openai-service.ts"; +addEventListener("beforeunload", (ev: any) => { + console.error( + "ALERTA: La función se va a apagar. Razón:", + ev?.detail?.reason, + ); +}); + export type DataAsignaturaSugerida = { nombre: Tables<"asignaturas">["nombre"]; codigo?: Tables<"asignaturas">["codigo"];