Skip to content

feat(services): start quota threshold notifier job at server boot (#1212) - #1483

Open
lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:feat/1212-start-quota-notifier-job-at-boot
Open

lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:feat/1212-start-quota-notifier-job-at-boot

Conversation

@lienhoatienphung-svg

Copy link
Copy Markdown

Summary

Wires and starts createQuotaNotifierJob at server boot in src/index.ts, persists sent quota threshold notifications in PostgreSQL (PgQuotaNotificationStore), and integrates the job into graceful shutdown so in-flight checks complete cleanly before database pools close.

Closes #1212

Key Changes

  1. Environment & Config (src/config/env.ts, src/config/index.ts):
    • Added QUOTA_NOTIFIER_ENABLED (default true outside test), QUOTA_NOTIFIER_INTERVAL_MS (default 300000), and QUOTA_DEFAULT_MONTHLY_LIMIT (default 10000).
  2. Quota Notifier Persistence & Shutdown (src/services/quotaNotifier.ts):
    • Added PgQuotaNotificationStore backed by quota_notifications_sent(developer_id, period, threshold, sent_at) for idempotent cross-restart notification tracking.
    • Added loadDeveloperQuotasFromDb to resolve developer monthly limits from api_keys, developers.plan_overrides, or active webhooks subscriptions.
    • Extended QuotaNotifierJob with beginShutdown() and awaitIdle() to satisfy ShutdownSubsystem.
  3. Server Boot & Graceful Shutdown (src/index.ts):
    • Instantiated quotaNotifierJob, registered it in shutdownSubsystems, started it in startServer() when config.quotaNotifier.enabled is true, and stopped it in closeAllDataResources().

Verification

  • Verified with npx jest src/services/quotaNotifier.test.ts (37/37 passed).

Payout Wallet (Base Mainnet USDC)

0x3806cd592a508d1992Ed007C2F53de251C2E7452

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.

Start quota threshold notifier job at boot

1 participant