Skip to content

feat(tmmongo): add WithSettingsCheckInterval for tenant config revalidation #376

@jeffersonrodrigues92

Description

@jeffersonrodrigues92

Summary

Add WithSettingsCheckInterval option to tmmongo.Manager (MongoDB tenant manager), matching the existing implementation in tmpostgres.Manager.

Problem

When a tenant is suspended or purged, the PostgreSQL manager detects this via periodic revalidation and evicts the cached connection. The MongoDB manager has no such mechanism — cached connections remain stale until pod restart.

This affects all components using tmmongo.Manager:

  • CRM (MongoDB only)
  • Onboarding (MongoDB manager)
  • Transaction (MongoDB manager)

Current State

  • tmpostgres.Manager has WithSettingsCheckInterval + revalidatePoolSettings goroutine ✅
  • tmmongo.Manager does NOT have this option ❌

Proposed Implementation

Port the revalidation logic from tmpostgres.Manager to tmmongo.Manager:

  1. Add settingsCheckInterval time.Duration field
  2. Add lastSettingsCheck map[string]time.Time per-tenant tracking
  3. Add WithSettingsCheckInterval(d time.Duration) Option
  4. In GetConnection, check if interval has passed → spawn goroutine
  5. revalidatePoolSettings calls client.GetTenantConfig → if TenantSuspendedErrorCloseConnection

Behavior

  • Per-tenant, lazy evaluation (only when requests arrive)
  • Fire-and-forget goroutine (non-blocking)
  • Default: 30s (same as PostgreSQL)
  • Configurable via the option

Acceptance Criteria

  • tmmongo.WithSettingsCheckInterval option available
  • Suspended/purged tenants evicted from MongoDB pool after interval
  • Next request creates fresh connection with new credentials
  • Tests covering revalidation and eviction

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions