Skip to content

fix(db): use TransactionTemplate for batched spot cleanup#295

Merged
arunderwood merged 2 commits intomainfrom
fix/batched-spot-cleanup
Jan 6, 2026
Merged

fix(db): use TransactionTemplate for batched spot cleanup#295
arunderwood merged 2 commits intomainfrom
fix/batched-spot-cleanup

Conversation

@arunderwood
Copy link
Copy Markdown
Owner

Summary

  • Fixes Spring self-invocation problem where @Transactional on deleteBatch() was ignored when called from executeCleanup() in the same class
  • Switches to programmatic TransactionTemplate to ensure each 100k-row batch commits independently
  • This allows the cleanup task to delete millions of expired spots without long-running transaction timeouts

Background

The previous PR (#294) added batched deletion but used @Transactional annotation which doesn't work for internal method calls (Spring's proxy-based AOP limitation). After deployment, the cleanup task continued failing (44 consecutive failures).

Test plan

  • Unit tests pass with mocked TransactionTemplate
  • Build passes with delta coverage
  • Deploy to Render
  • Verify spot-cleanup task succeeds (check consecutive_failures = 0 in scheduled_tasks table)

The previous @transactional approach didn't work because deleteBatch()
is called internally from executeCleanup() in the same class, bypassing
Spring's proxy-based AOP (self-invocation problem).

Switch to programmatic TransactionTemplate to ensure each batch commits
in its own transaction, preventing long-running transactions when
deleting millions of expired spots.
@arunderwood arunderwood force-pushed the fix/batched-spot-cleanup branch from 2efa7c1 to cd49860 Compare January 6, 2026 06:05
Cover the null branch in SpotCleanupService.deleteBatch() to satisfy
delta coverage requirements (80% branch coverage). The null case occurs
when TransactionTemplate.execute() returns null during a rollback.
@arunderwood arunderwood merged commit 32f0e55 into main Jan 6, 2026
12 checks passed
@arunderwood arunderwood deleted the fix/batched-spot-cleanup branch January 6, 2026 06:24
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