Skip to content

Fan out dunning customer processing - #6214

Open
lago-claude-ai-agent[bot] wants to merge 4 commits into
mainfrom
fix/claude-fan-out-dunning-processing
Open

Fan out dunning customer processing#6214
lago-claude-ai-agent[bot] wants to merge 4 commits into
mainfrom
fix/claude-fan-out-dunning-processing

Conversation

@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor

Dispatches eligible dunning customers to unique per-customer jobs instead of evaluating them serially in the hourly bulk job. The dispatcher loads only customer IDs in batches, while each bounded job preserves the existing dunning behavior.

## Context

The hourly dunning job evaluates every eligible customer serially, causing its runtime to grow with the customer population.

## Description

Dispatch eligible customers to unique per-customer jobs while preserving the existing evaluation behavior and eligibility scope.

Signed-off-by: lago-claude-ai-agent[bot] <297187938+lago-claude-ai-agent[bot]@users.noreply.github.com>
@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor Author

Held: CI is not green on this PR; not reviewed. Re-run CI, then re-review.

Checks: https://github.com/getlago/lago-api/pull/6214/checks

Keep frozen model annotations aligned with the database schema.

Signed-off-by: lago-claude-ai-agent[bot] <297187938+lago-claude-ai-agent[bot]@users.noreply.github.com>
@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor Author
  • CI hold: restored the generated item metadata column comments required by the frozen annotation check.

@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor Author

Held: CI is not green on this PR; not reviewed. Re-run CI, then re-review.

Checks: https://github.com/getlago/lago-api/pull/6214/checks

require "rails_helper"

RSpec.describe DunningCampaigns::ProcessCustomerJob do
let(:customer) { build(:customer) }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To fix the build, this should be

Suggested change
let(:customer) { build(:customer) }
let(:customer) { create(:customer) }

Signed-off-by: lago-claude-ai-agent[bot] <297187938+lago-claude-ai-agent[bot]@users.noreply.github.com>
@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor Author
  • Persisted the customer fixture so the job can serialize and execute it successfully.

@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor Author

Hold: customer eligibility is only checked before enqueueing, so the new asynchronous boundary can mutate an ineligible customer.

  • Recheck customer.organization.auto_dunning_enabled? and customer.exclude_from_dunning_campaign? in ProcessCustomerService before updating counters or scheduling attempts, with a regression spec for eligibility changing after dispatch; otherwise an excluded or disabled customer can regain dunning attempt state and trigger the finished webhook while ProcessAttemptService correctly skips payment.

Signed-off-by: lago-claude-ai-agent[bot] <297187938+lago-claude-ai-agent[bot]@users.noreply.github.com>
@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor Author
  • The job spec uses a persisted customer fixture so its argument can be serialized.
  • Rechecked both eligibility flags before customer processing and added queued-boundary regression coverage for both changes.

@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor Author

PASS: The fan-out preserves existing dunning behavior in unique per-customer jobs, and regression coverage verifies delegation plus eligibility changes after dispatch.

@lago-claude-ai-agent
lago-claude-ai-agent Bot marked this pull request as ready for review August 27, 2026 17:15
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.

1 participant