Erinnerungs-Function: Diagnose-Logging pro Nutzer
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
7d45724ef2
commit
0ce4b2cb19
1 changed files with 20 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import {onSchedule} from "firebase-functions/v2/scheduler";
|
import {onSchedule} from "firebase-functions/v2/scheduler";
|
||||||
|
import {logger} from "firebase-functions";
|
||||||
import * as admin from "firebase-admin";
|
import * as admin from "firebase-admin";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -149,7 +150,14 @@ export const sendDailyReminders = onSchedule(
|
||||||
for (const userDoc of users.docs) {
|
for (const userDoc of users.docs) {
|
||||||
const user = userDoc.data() as UserDoc;
|
const user = userDoc.data() as UserDoc;
|
||||||
const tokens = user.fcmTokens ?? [];
|
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 timezone = user.timezone ?? "Europe/Berlin";
|
||||||
const reminderTime = user.reminderTime ?? "09:00";
|
const reminderTime = user.reminderTime ?? "09:00";
|
||||||
|
|
@ -165,7 +173,10 @@ export const sendDailyReminders = onSchedule(
|
||||||
|
|
||||||
// Höchstens eine Erinnerung pro Tag.
|
// Höchstens eine Erinnerung pro Tag.
|
||||||
const todayKey = dateKey(local);
|
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(
|
const summary = await collectDueTasks(
|
||||||
db,
|
db,
|
||||||
|
|
@ -174,6 +185,13 @@ export const sendDailyReminders = onSchedule(
|
||||||
timezone
|
timezone
|
||||||
);
|
);
|
||||||
const taskCount = summary.watering.length + summary.fertilizing.length;
|
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;
|
if (taskCount === 0) continue;
|
||||||
|
|
||||||
const response = await admin.messaging().sendEachForMulticast({
|
const response = await admin.messaging().sendEachForMulticast({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue