Skip to content

feat(deadline-monitor): scheduled contract deadline monitor - #168

Merged
SudiptaPaul-31 merged 3 commits into
Lumina-eX:mainfrom
modecodes:153-scheduled-contract-deadline-monitor
Jul 26, 2026
Merged

feat(deadline-monitor): scheduled contract deadline monitor#168
SudiptaPaul-31 merged 3 commits into
Lumina-eX:mainfrom
modecodes:153-scheduled-contract-deadline-monitor

Conversation

@modecodes

Copy link
Copy Markdown
Contributor

Summary

Adds a scheduled service that monitors milestone deadlines so overdue work and approaching due dates are surfaced automatically, instead of relying on someone checking manually. This is a net-new feature — no existing deadline-tracking service was in place.

What was built

  • lib/deadline-monitor/service.tsDeadlineMonitorService.runCheck() runs two independent, idempotent sweeps:

    1. Upcoming deadline reminders — milestones due within the next 24 hours that haven't been reminded yet get a one-time notification sent to both the client and the freelancer.
    2. Overdue flagging — milestones whose due date has passed get flagged is_overdue = true and both parties are notified.

    Both sweeps skip milestones already in a terminal status (approved, paid, rejected), and both are guarded by bookkeeping columns (reminder_sent_at, is_overdue) so re-running the sweep on a tight interval never sends duplicate notifications.

  • lib/notifications.ts — extended NotificationType with milestone_deadline_approaching and milestone_overdue, so these events reuse the existing notifications table/API/pagination instead of introducing a parallel event log.

  • components/dashboard/notification-item.tsx — added icon/label/description handling for the two new notification types so they render properly in the dashboard notification panel.

  • scripts/deadline-monitor.ts — standalone worker process (npm run deadline-monitor), following the same long-running-process pattern as the existing scripts/sync-worker.ts. Runs an initial check on startup, then repeats on an interval controlled by DEADLINE_CHECK_INTERVAL_MS (default 5 minutes).

  • lib/db/migrations/007_deadline_monitor.sql — adds is_overdue, overdue_at, reminder_sent_at to milestones, plus a partial index for the overdue sweep query.

  • docs/deadline-monitor.md — architecture, configuration, and testing docs.

Acceptance criteria

  • ✅ Accurate detection — overdue milestones are identified via a due_date < NOW() sweep, excluding already-terminal milestones.
  • ✅ Timely notifications — reminders fire 24h before the deadline; overdue notices fire as soon as the sweep runs past the due date.
  • ✅ Automated status updates — milestones are automatically flagged is_overdue with an overdue_at timestamp.
  • ✅ Reminder events generated — both reminder and overdue events are logged via the notifications system and surfaced in the existing dashboard notification panel.

Testing

Added __tests__/deadline-monitor/service.test.ts and types.test.ts, covering: no-op behavior when nothing is due, reminder notification + bookkeeping, overdue flagging + notification, and both sweeps running independently within a single runCheck() call. Full suite passes; no new lint or type errors introduced.

Closes #153

…monitor' into 153-scheduled-contract-deadline-monitor

# Conflicts:
#	components/dashboard/notification-item.tsx
#	lib/notifications.ts
@SudiptaPaul-31
SudiptaPaul-31 merged commit 732b285 into Lumina-eX:main Jul 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Scheduled Contract Deadline Monitor

2 participants