Conversation
2dd5d9f to
7c1fd0b
Compare
- Added ShiftReminderContext for managing shift-end reminder modal and notifications. - Integrated Agenda for scheduling shift reminders and auto-clockout jobs. - Updated API to handle user agreement for auto-clockout. - Enhanced E2E tests for shift reminder scenarios including "Agree to Clock Out" and "Continue Working". - Refactored existing tests to utilize new auth header retrieval method. - Updated package dependencies to include @agendajs/mongo-backend and agenda. removed clock monitor since we are using agenda js removing clock monitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Replaces the old
ClockMonitorServicepolling loop (asetIntervalthat scanned all active clock events every 30 seconds) with Agenda.js — a MongoDB-backed job scheduler. This eliminates unnecessary database scans and ties each job precisely to the clock-in event that triggered it.How Agenda.js Works
Agenda stores scheduled jobs in MongoDB (the
agendajobscollection). Each job has a name, anextRunAttimestamp, and a payload. When a job's scheduled time arrives, Agenda processes it and executes the registered handler. Key configuration:processEvery: "30 seconds"— Agenda polls MongoDB every 30s to pick up due jobs.defaultLockLifetime: 10_000— Jobs are locked for up to 10s to prevent double-processing across server restarts.Three Jobs Scheduled per Clock-In
shift-4h-reminderstartTime + 4hshift-end-reminderstartTime + 7h 45mshift-auto-clockoutstartTime + 8hAll three jobs are scheduled atomically when the user clocks in (
scheduleClockJobs()) and cancelled atomically when the user clocks out (cancelClockJobs()).What Changed
Backend
backend/src/services/agenda.service.ts— Agenda instance, job definitions,initAgenda()/stopAgenda()/scheduleClockJobs()/cancelClockJobs()helpers.backend/src/services/clock-monitor.service.ts— the oldsetInterval-based polling service. Replaced entirely by Agenda.clock.service.ts—clockIn()now callsscheduleClockJobs();clockOut()callscancelClockJobs(). AddedagreeAutoClockout()to mark a session as consented to auto-clockout.POST /v1/clock/:id/agree-clockoutfor the frontend modal "Agree to Clock Out" button.server.ts— CallsinitAgenda()on startup (skipped intestenv) andstopAgenda()on graceful shutdown.backend/package.json— Addedagendaand@agendajs/mongo-backend.Frontend
src/features/notifications/ShiftReminderContext.tsx— Listens on the SSE stream forshift-end-remindermessages, opens a modal asking "Continue Working" or "Agree to Clock Out", and calls the new agree endpoint.src/ui/AppLayout.tsx— Wraps the app inShiftReminderContext.src/lib/api.ts— AddedagreeAutoClockout(clockEventId)API helper.E2E Tests
e2e/shift-reminder.spec.ts— Full coverage of the shift-end reminder flow: modal appears after 7h 45m, "Agree" sets the flag, "Continue Working" dismisses without flagging.e2e/clock-breaks.spec.ts,e2e/work.spec.ts,e2e/pulsevault.spec.ts,e2e/tickets.spec.ts— Added explicitAuthorization: Bearerheaders forpage.requestAPI calls (better-auth useslocalStoragetokens, not cookies, sopage.requesthad no auth).Acceptance Criteria
notificationService.create()autoClockoutAgreed=trueand triggers auto-clockout at 8hclock-monitor.service.tsremoved — no polling loops remain