Skip to content

feat: contribution reminder scheduler with BullMQ (closes #4)#13

Open
Vyacheslav-Tomashevskiy wants to merge 1 commit into
coopfinance:mainfrom
Vyacheslav-Tomashevskiy:feat/contribution-reminder-scheduler
Open

feat: contribution reminder scheduler with BullMQ (closes #4)#13
Vyacheslav-Tomashevskiy wants to merge 1 commit into
coopfinance:mainfrom
Vyacheslav-Tomashevskiy:feat/contribution-reminder-scheduler

Conversation

@Vyacheslav-Tomashevskiy

Copy link
Copy Markdown

Closes #4

What

Wires the bullmq + ioredis deps (already in package.json, previously unused) into a working contribution-reminder pipeline.

Changes

  • AppModuleBullModule.forRoot({ connection }), Redis connection parsed from REDIS_URL (host/port/user/password/db).
  • reminder.queue.tscontribution-reminders queue name, ReminderJobData payload type, and redisConnectionFromEnv() helper.
  • ReminderProcessor (WorkerHost) — for each job payload { groupId, memberAddress, period, dueDate } creates a contribution_due Notification via NotificationsService.create(...); if the member has an email on file it logs an email intent with a // TODO nodemailer stub.
  • ReminderScheduler@Cron(CronExpression.EVERY_DAY_AT_9AM): for every active group, derives the current contribution period, and if the due date is within the lead window enqueues one reminder per active member who has not yet contributed that period.
  • Deterministic jobId = groupId:member:period → exactly one reminder per member per period even though the cron runs on each day of the lead window; queue counts are logged for monitoring.
  • Unit test (mocked queue + Prisma) covering: enqueue-only-for-non-contributors, outside-window skip, all-contributed skip.

Acceptance criteria

  • BullMQ queue + processor implemented
  • Daily cron enqueues reminders for due-soon members
  • Notification record created in DB when the job runs
  • Redis connection configurable via REDIS_URL
  • Queue monitored (job counts logged each run)
  • Unit test: mocked queue verifies jobs enqueued correctly

Notes

  • The schema has no per-group contribution_period_days field yet, so the period length is configurable via CONTRIBUTION_PERIOD_DAYS (default 30) and CONTRIBUTION_REMINDER_LEAD_DAYS (default 3), and the current period is derived from each group's createdAt. currentPeriod() is isolated so a per-group governance value can drop in later without touching the enqueue logic.
  • Added a minimal jest config block (ts-jest) so the new suite actually runs — the repo had "test": "jest" but no jest config.
  • The 3 pre-existing tsc errors on main (stellar.service.ts, notifications.service.ts) are untouched and unrelated to this change.

Verification

npx jest reminder.scheduler   # 3 passed
npm run build                 # no new errors from added files

Wire up the bullmq/ioredis deps that were already in package.json but
unused into a daily contribution-reminder pipeline:

- BullModule.forRoot() in AppModule (Redis connection from REDIS_URL)
- contribution-reminders queue + ReminderProcessor (persists a
  contribution_due Notification, email stubbed with a TODO)
- ReminderScheduler @Cron(EVERY_DAY_AT_9AM): for each active group,
  enqueues a reminder for every active member who has not contributed
  in the current period, once the due date is within the lead window
- deterministic jobId dedupes to one reminder per member per period
- unit test (mocked queue + prisma) covering enqueue / outside-window /
  already-contributed
- minimal jest config so the suite runs; REDIS_URL + period/lead env docs
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.

Implement contribution reminder scheduler using BullMQ

1 participant