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) => {
|
notificationsRouter.post("/refresh", async (_req, res) => {
|
||||||
|
console.log("[Refresh] Request received");
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
+2
-1
@@ -8,12 +8,13 @@ export function startScheduler(): void {
|
|||||||
|
|
||||||
intervalId = setInterval(async () => {
|
intervalId = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
|
console.log("[Scheduler] Checking devices...");
|
||||||
const devices = await db.getAll();
|
const devices = await db.getAll();
|
||||||
for (const d of devices) {
|
for (const d of devices) {
|
||||||
await sendPushToDevice(d.fcmToken);
|
await sendPushToDevice(d.fcmToken);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("scheduler tick failed", err);
|
console.error("[Scheduler] Tick failed", err);
|
||||||
}
|
}
|
||||||
}, 5 * 60 * 1000);
|
}, 5 * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ function lastNotifiedMs(row: StoredRow | undefined): number | undefined {
|
|||||||
return 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(
|
function stringifyData(
|
||||||
payload: Record<string, unknown>
|
payload: Record<string, unknown>
|
||||||
): Record<string, string> {
|
): Record<string, string> {
|
||||||
@@ -41,6 +47,8 @@ export async function sendPushToDevice(
|
|||||||
last !== undefined &&
|
last !== undefined &&
|
||||||
now - last < notifyThresholdMs(row?.testMode)
|
now - last < notifyThresholdMs(row?.testMode)
|
||||||
) {
|
) {
|
||||||
|
const device = { id: row?.id ?? "unknown" };
|
||||||
|
console.log("[Skip] Recently notified:", device.id);
|
||||||
return "skipped";
|
return "skipped";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +59,9 @@ export async function sendPushToDevice(
|
|||||||
type: "WAKEUP_PING",
|
type: "WAKEUP_PING",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const token = tokenHint(fcmToken);
|
||||||
|
console.log("[Push] Sending to:", token);
|
||||||
|
|
||||||
await messaging.send({
|
await messaging.send({
|
||||||
token: device.fcmToken,
|
token: device.fcmToken,
|
||||||
apns: {
|
apns: {
|
||||||
@@ -71,9 +82,10 @@ export async function sendPushToDevice(
|
|||||||
if (persisted !== undefined) {
|
if (persisted !== undefined) {
|
||||||
await db.update(persisted.id, { lastNotifiedAt: Date.now() });
|
await db.update(persisted.id, { lastNotifiedAt: Date.now() });
|
||||||
}
|
}
|
||||||
|
console.log("[Push] Success:", token);
|
||||||
return "sent";
|
return "sent";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("FCM send failed", err);
|
console.error("[Push] Failed:", err);
|
||||||
return "failed";
|
return "failed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user