From 0ce4b2cb196994c576a21f67c2075f26ccd7420a Mon Sep 17 00:00:00 2001 From: cschlaefke Date: Sun, 19 Jul 2026 14:55:50 +0200 Subject: [PATCH] Erinnerungs-Function: Diagnose-Logging pro Nutzer Co-Authored-By: Claude Fable 5 --- functions/src/reminders.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/functions/src/reminders.ts b/functions/src/reminders.ts index 4e0cb2f..020c4cd 100644 --- a/functions/src/reminders.ts +++ b/functions/src/reminders.ts @@ -1,4 +1,5 @@ import {onSchedule} from "firebase-functions/v2/scheduler"; +import {logger} from "firebase-functions"; import * as admin from "firebase-admin"; /** @@ -149,7 +150,14 @@ export const sendDailyReminders = onSchedule( for (const userDoc of users.docs) { const user = userDoc.data() as UserDoc; const tokens = user.fcmTokens ?? []; - if (tokens.length === 0 || !user.householdId) continue; + if (tokens.length === 0 || !user.householdId) { + logger.info("Übersprungen: kein Token oder kein Haushalt", { + uid: userDoc.id, + tokens: tokens.length, + householdId: user.householdId ?? null, + }); + continue; + } const timezone = user.timezone ?? "Europe/Berlin"; const reminderTime = user.reminderTime ?? "09:00"; @@ -165,7 +173,10 @@ export const sendDailyReminders = onSchedule( // Höchstens eine Erinnerung pro Tag. const todayKey = dateKey(local); - if (user.lastReminderSentOn === todayKey) continue; + if (user.lastReminderSentOn === todayKey) { + logger.info("Übersprungen: heute schon erinnert", {uid: userDoc.id}); + continue; + } const summary = await collectDueTasks( db, @@ -174,6 +185,13 @@ export const sendDailyReminders = onSchedule( timezone ); const taskCount = summary.watering.length + summary.fertilizing.length; + logger.info("Erinnerungs-Slot erreicht", { + uid: userDoc.id, + reminderTime, + timezone, + tokens: tokens.length, + taskCount, + }); if (taskCount === 0) continue; const response = await admin.messaging().sendEachForMulticast({