chore(logging): normalize wakeup flow observability with timings and summaries
Standardize console prefixes across scheduler, push, refresh, register, auth, and debug endpoints. Add pass-level scheduler summaries, elapsed-time logs, and masked-token-only push failure messages while reducing per-device noise in scheduler loops.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { db, type StoredRow } from "../db/fcmTokens.js";
|
||||
import { errorMessage, formatElapsedMs } from "../util/formatElapsed.js";
|
||||
import { maskToken } from "../util/maskToken.js";
|
||||
import { messaging } from "./firebase.js";
|
||||
|
||||
@@ -46,6 +47,7 @@ export async function sendPushToDevice(
|
||||
fcmToken: string,
|
||||
payload: Record<string, unknown> = {}
|
||||
): Promise<"sent" | "skipped" | "failed"> {
|
||||
const suffix = maskToken(fcmToken);
|
||||
const row = await db.getByFcmToken(fcmToken);
|
||||
const now = Date.now();
|
||||
const last = lastNotifiedMs(row);
|
||||
@@ -54,23 +56,20 @@ export async function sendPushToDevice(
|
||||
last !== undefined &&
|
||||
now - last < notifyThresholdMs(row?.testMode)
|
||||
) {
|
||||
const device = { id: row?.id ?? "unknown" };
|
||||
console.log("[Skip] Recently notified:", device.id);
|
||||
return "skipped";
|
||||
}
|
||||
|
||||
const sendStarted = Date.now();
|
||||
console.log("[Push] Send attempt, token suffix:", suffix);
|
||||
|
||||
try {
|
||||
const device = { fcmToken };
|
||||
const data: Record<string, string> = {
|
||||
...stringifyData(payload),
|
||||
type: "WAKEUP_PING",
|
||||
};
|
||||
|
||||
const token = maskToken(fcmToken);
|
||||
console.log("[Push] Sending to:", token);
|
||||
|
||||
await messaging.send({
|
||||
token: device.fcmToken,
|
||||
token: fcmToken,
|
||||
apns: {
|
||||
headers: {
|
||||
"apns-push-type": "background",
|
||||
@@ -89,10 +88,21 @@ export async function sendPushToDevice(
|
||||
if (persisted !== undefined) {
|
||||
await db.update(persisted.id, { lastNotifiedAt: Date.now() });
|
||||
}
|
||||
console.log("[Push] Success:", token);
|
||||
console.log(
|
||||
"[Push] Send completed in",
|
||||
formatElapsedMs(Date.now() - sendStarted) + ",",
|
||||
"token suffix:",
|
||||
suffix
|
||||
);
|
||||
return "sent";
|
||||
} catch (err) {
|
||||
console.error("[Push] Failed:", err);
|
||||
console.error(
|
||||
"[Push] Send failed in",
|
||||
formatElapsedMs(Date.now() - sendStarted) + ",",
|
||||
"token suffix:",
|
||||
suffix + ":",
|
||||
errorMessage(err)
|
||||
);
|
||||
return "failed";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user