refactor: extract shared IntervalScheduler base class (#1694)

Merged
LU
3mo ago
+160-163

Summary

Extract the common start/stop/tick scaffold from BirthdayScheduler, ReminderScheduler, and GiveawayScheduler into a reusable IntervalScheduler base class that manages:

  • Timer and client lifecycle (timer, client fields)
  • Concurrent tick prevention (tickInProgress guard)
  • Standard start/stop methods
  • Template-method tick() with error handling

Subclasses implement execute() for domain-specific logic and override onStart() for custom initialization (e.g., running tick immediately on startup for birthday/reminder schedulers).

Resolves code duplication and allows removal of both reminderScheduler and giveawayScheduler from sonar-project.properties cpd.exclusions.

Changes

  • New: IntervalScheduler base class with protected lifecycle methods
  • Refactored: BirthdayScheduler, ReminderScheduler, GiveawayScheduler to extend the base class
  • Updated: sonar-project.properties to remove duplication exclusions for reminder and giveaway schedulers

Test Plan

  • Full bot test suite passes (all 3 schedulers' tests remain unchanged)
  • Type checking passes
  • Lint checks pass
  • Sonar duplication gate passes (previously excluded schedulers no longer flagged as duplicates)

Closes #1694


Summary by cubic

Refactored the birthday, reminder, and giveaway schedulers to share a new IntervalScheduler base, removing duplicated lifecycle code and standardizing error handling. Re-enabled Sonar CPD checks by removing scheduler exclusions (closes #1694).

  • Refactors

    • Added IntervalScheduler with start/stop, concurrency guard, and centralized error handling.
    • Schedulers now use onStart() for startup work and execute() for periodic tasks; birthday/reminder run an immediate tick on start.
    • Removed packages/bot/src/utils/general/reminderScheduler.ts and .../giveawayScheduler.ts from sonar.cpd.exclusions.
  • Bug Fixes

    • Removed stray closing braces causing parse errors.
    • Dedented execute() bodies after refactor.
    • Dropped unused Client imports.

Summary by CodeRabbit

  • Refactor
    • Standardized birthday, giveaway, and reminder scheduling on a shared interval-based scheduler.
    • Prevented overlapping scheduler runs and added consistent error handling.
    • Preserved existing birthday, giveaway, and reminder processing behavior.
    • Improved scheduler startup logging and testability.
  • Chores
    • Updated code-quality analysis settings to include scheduler modules.