Skip to content

feat: add scheduled job to purge expired idempotency keys and impleme… - #555

Open
Johnsource-hub wants to merge 1 commit into
scout-off:mainfrom
Johnsource-hub:Add-a-scheduled-job-to-purge-expired-idempotency-keys
Open

feat: add scheduled job to purge expired idempotency keys and impleme…#555
Johnsource-hub wants to merge 1 commit into
scout-off:mainfrom
Johnsource-hub:Add-a-scheduled-job-to-purge-expired-idempotency-keys

Conversation

@Johnsource-hub

Copy link
Copy Markdown

#closes
#481

Summary

Adds a periodic cleanup job that deletes expired idempotency-key rows from the database to prevent unbounded growth.
Wires the purge job into application startup and exposes a manual script to run the purge from CLI/cron.
Adds tests that assert expired rows are removed while active rows are preserved.
Why

idempotency_keys rows were never removed; this leads to unbounded table growth. The purge preserves in-window keys and deletes expired ones.
Implementation notes

Purge logic:
Function purgeExpiredIdempotencyKeys(now?: number): number deletes rows with expires_at <= now and returns the number of deleted rows.
A scheduler startIdempotencyPurgeJob(intervalMs?: number) uses setInterval to run the purge at a configurable cadence.
getIdempotencyRecord and recordIdempotencyKey follow the same expiry semantics used by the middleware so behavior for in-window keys is unchanged.

and test OK in isolation.
Acceptance checklist

Expired idempotency key rows are deleted by the purge
Unexpired rows are not deleted
Purge runs on a configurable periodic schedule at startup
Manual npm run purge:idempotency-keys runner added
Regression test asserts behavior

@Petah1

Petah1 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

resolve conflict

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