chore(obs): add lightweight console logs for scheduler and push
Log scheduler ticks, refresh requests, dedupe skips by device id, push attempt/success with token hints, and push failures without extra sensitive fields.
This commit is contained in:
@@ -8,6 +8,7 @@ notificationsRouter.get("/", (_req, res) => {
|
||||
});
|
||||
|
||||
notificationsRouter.post("/refresh", async (_req, res) => {
|
||||
console.log("[Refresh] Request received");
|
||||
const now = Date.now();
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -8,12 +8,13 @@ export function startScheduler(): void {
|
||||
|
||||
intervalId = setInterval(async () => {
|
||||
try {
|
||||
console.log("[Scheduler] Checking devices...");
|
||||
const devices = await db.getAll();
|
||||
for (const d of devices) {
|
||||
await sendPushToDevice(d.fcmToken);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("scheduler tick failed", err);
|
||||
console.error("[Scheduler] Tick failed", err);
|
||||
}
|
||||
}, 5 * 60 * 1000);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,12 @@ function lastNotifiedMs(row: StoredRow | undefined): number | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Short token fingerprint for logs (not the full FCM token). */
|
||||
function tokenHint(token: string): string {
|
||||
if (token.length <= 16) return token;
|
||||
return `${token.slice(0, 8)}…${token.slice(-4)}`;
|
||||
}
|
||||
|
||||
function stringifyData(
|
||||
payload: Record<string, unknown>
|
||||
): Record<string, string> {
|
||||
@@ -41,6 +47,8 @@ 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";
|
||||
}
|
||||
|
||||
@@ -51,6 +59,9 @@ export async function sendPushToDevice(
|
||||
type: "WAKEUP_PING",
|
||||
};
|
||||
|
||||
const token = tokenHint(fcmToken);
|
||||
console.log("[Push] Sending to:", token);
|
||||
|
||||
await messaging.send({
|
||||
token: device.fcmToken,
|
||||
apns: {
|
||||
@@ -71,9 +82,10 @@ export async function sendPushToDevice(
|
||||
if (persisted !== undefined) {
|
||||
await db.update(persisted.id, { lastNotifiedAt: Date.now() });
|
||||
}
|
||||
console.log("[Push] Success:", token);
|
||||
return "sent";
|
||||
} catch (err) {
|
||||
console.error("FCM send failed", err);
|
||||
console.error("[Push] Failed:", err);
|
||||
return "failed";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user