diff --git a/docker-compose.yml b/docker-compose.yml index 4c30427..ceb6981 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: - DATABASE_PATH=/app/data/quietthanks.db - NEXT_PUBLIC_VAPID_PUBLIC_KEY=BIKukAq5-KPwJAMpksxD7UNL8XfF-oJOI0CLGGZQAY93igZgf1PYa9MVvS8GaBv-vv9ckcXPCEKdzWDCtOyQpKg - VAPID_PRIVATE_KEY=IBkQ14BLKFCg2PmGOWheC7xfYHS5J49vXS8duHCeDBw - - VAPID_EMAIL=mailto:admin@quietthanks.local + - VAPID_EMAIL=mailto:admin@example.com - TZ=Australia/Perth scheduler: diff --git a/src/app/api/notifications/send/route.ts b/src/app/api/notifications/send/route.ts index 4643885..3830c3a 100644 --- a/src/app/api/notifications/send/route.ts +++ b/src/app/api/notifications/send/route.ts @@ -12,19 +12,28 @@ export async function POST() { // Format: HH:MM const timeString = `${currentHour.toString().padStart(2, "0")}:${currentMinute.toString().padStart(2, "0")}`; + console.log(`[Scheduler] Checking for reminders at ${timeString} (${now.toISOString()})`); + // Find users who have reminders enabled and time matches const users = await db .select() .from(schema.users) .where(and(eq(schema.users.reminderEnabled, 1), eq(schema.users.reminderTime, timeString))); + console.log(`[Scheduler] Found ${users.length} users with reminder time ${timeString}`); + let sent = 0; let failed = 0; for (const user of users) { + console.log(`[Scheduler] Processing user ${user.id} (Always: ${user.reminderAlways})`); + // Check if user has already made an entry today, unless they want reminders always if (user.reminderAlways !== 1) { - const today = now.toISOString().split("T")[0]; + const today = now.toISOString().split("T")[0]; // YYYY-MM-DD + // Ensure we use the user's local date if possible, but for now assuming server time matches user expectation + // since we enforced TZ=Australia/Perth + const entries = await db .select() .from(schema.entries) @@ -32,6 +41,7 @@ export async function POST() { .limit(1); if (entries.length > 0) { + console.log(`[Scheduler] User ${user.id} already has an entry for ${today}, skipping`); continue; // Already journaled today } } @@ -42,8 +52,11 @@ export async function POST() { .from(schema.pushSubscriptions) .where(eq(schema.pushSubscriptions.userId, user.id)); + console.log(`[Scheduler] User ${user.id} has ${subscriptions.length} subscriptions`); + for (const sub of subscriptions) { try { + console.log(`[Scheduler] Sending push to ${sub.endpoint.substring(0, 20)}...`); const success = await sendPushNotification( { endpoint: sub.endpoint,