Skip to content

fix(journeys): warm active-journey cache at boot + read-through findActive (EVO-1927)#102

Merged
dpaes merged 1 commit into
developfrom
danilocarneiro/evo-1927-jornadas-regressao-findactive-le-cache-vazio-apos-restart-do
Jun 25, 2026
Merged

fix(journeys): warm active-journey cache at boot + read-through findActive (EVO-1927)#102
dpaes merged 1 commit into
developfrom
danilocarneiro/evo-1927-jornadas-regressao-findactive-le-cache-vazio-apos-restart-do

Conversation

@daniloleonecarneiro

Copy link
Copy Markdown

Summary

Regression: after an evo-flow restart, JourneysService.findActive() read from an empty/stale Redis active-journey index (no warm-up on boot). The JourneyTriggerProcessor then matched every event against ZERO journeys, so event-based triggers died silently on each deploy (Found 0 active journeys while Postgres had 56 active). Manual triggers were unaffected (they bypass the cache).

Two layers of defense:

  1. Boot warm-upJourneysService.warmActiveJourneysCache() loads active journeys from Postgres and populates the cache. The JourneyTriggerProcessor calls it in onModuleInit BEFORE subscribing to journey-triggers, so the first event matches the real journey set. Best-effort: a warm-up failure does not block the consumer.
  2. Read-through in findActive() — on a cache miss (cache returns 0), fall through to the DB as source of truth and repopulate the cache so subsequent reads hit Redis again.
  3. Observability — warn when the cache returns 0 while the DB has active journeys (the regression signature).

Test plan

  • npx tsc -b clean.
  • npx jest on journeys.service.spec.ts + journey-trigger-processor.service.spec.ts: 24/24 green.
    • findActive: cache-warm hit (no DB), empty-cache read-through + repopulate, observability warn, both-empty no-warn, best-effort on cache-write failure.
    • warmActiveJourneysCache: loads + populates, swallows per-journey write failures.
    • processor boot: warm-up runs in order before init/consume, consumer still starts when warm-up throws, no warm-up in non-journey-worker modes.

Notas

  • Read-through and warm-up are independent; either alone fixes the regression, together they cover both the cold first event and any later cache eviction/TTL expiry.
  • No schema/migration changes.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @daniloleonecarneiro, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@daniloleonecarneiro daniloleonecarneiro self-assigned this Jun 25, 2026

@dpaes dpaes left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — deep adversarial review (card + authoritative diff + real code): acceptance criteria met, no blocking findings. Merge intentionally held to land in the coordinated dependency-order pass. Branch is clean vs develop.

@dpaes dpaes merged commit 4b1ae37 into develop Jun 25, 2026
3 checks passed
@dpaes dpaes deleted the danilocarneiro/evo-1927-jornadas-regressao-findactive-le-cache-vazio-apos-restart-do branch June 25, 2026 21:21
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.

2 participants