Skip to content

Commit 6a97d56

Browse files
committed
feat(jobs): add ownership snapshot cleanup job scaffold
Closes #136
1 parent 85241c8 commit 6a97d56

8 files changed

Lines changed: 19887 additions & 0 deletions

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ API_VERSION=1.0.0
2525
ENABLE_API_VERSION_HEADER=true
2626
ENABLE_RESPONSE_TIMING=true
2727
ENABLE_REQUEST_LOGGING=true
28+
29+
# Ownership snapshot cleanup scaffold
30+
OWNERSHIP_SNAPSHOT_CLEANUP_ENABLED=false
31+
OWNERSHIP_SNAPSHOT_CLEANUP_INTERVAL_MINUTES=60
32+
OWNERSHIP_SNAPSHOT_RETENTION_DAYS=30
33+
OWNERSHIP_SNAPSHOT_CLEANUP_DRY_RUN=true
34+
OWNERSHIP_SNAPSHOT_TABLE_NAME=creator_ownership_snapshots

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,7 @@ readinessProbe:
171171
- Browse the maintainer issue inventory in [docs/open-source/issue-backlog.md](./docs/open-source/issue-backlog.md).
172172
- Review [SECURITY.md](./SECURITY.md) before reporting vulnerabilities.
173173
- Use the issue templates in [`.github/ISSUE_TEMPLATE`](./.github/ISSUE_TEMPLATE) for new scoped work.
174+
175+
## Indexer and ownership operations
176+
177+
- Ownership snapshot cleanup scaffold: [docs/indexer/ownership-snapshot-cleanup.md](./docs/indexer/ownership-snapshot-cleanup.md)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Ownership Snapshot Cleanup Scaffold
2+
3+
This scaffold adds a scheduled cleanup job that targets expired ownership snapshot rows.
4+
5+
The implementation is intentionally conservative:
6+
7+
- it runs only when explicitly enabled
8+
- it supports dry-run mode by default
9+
- it skips cleanup if the target table does not exist yet
10+
11+
## Environment variables
12+
13+
Use the following variables to control behavior:
14+
15+
- `OWNERSHIP_SNAPSHOT_CLEANUP_ENABLED` (default: `false`)
16+
- `OWNERSHIP_SNAPSHOT_CLEANUP_INTERVAL_MINUTES` (default: `60`)
17+
- `OWNERSHIP_SNAPSHOT_RETENTION_DAYS` (default: `30`)
18+
- `OWNERSHIP_SNAPSHOT_CLEANUP_DRY_RUN` (default: `true`)
19+
- `OWNERSHIP_SNAPSHOT_TABLE_NAME` (default: `creator_ownership_snapshots`)
20+
21+
## How cleanup works
22+
23+
On each run, the job computes a cutoff timestamp as:
24+
25+
`now - OWNERSHIP_SNAPSHOT_RETENTION_DAYS`
26+
27+
Then it checks whether the configured table exists.
28+
29+
- In dry-run mode, it only counts rows where `expiresAt < cutoff`.
30+
- In non-dry-run mode, it deletes rows where `expiresAt < cutoff`.
31+
32+
## Local validation steps
33+
34+
1. Configure `.env`:
35+
36+
```bash
37+
OWNERSHIP_SNAPSHOT_CLEANUP_ENABLED=true
38+
OWNERSHIP_SNAPSHOT_CLEANUP_INTERVAL_MINUTES=1
39+
OWNERSHIP_SNAPSHOT_RETENTION_DAYS=30
40+
OWNERSHIP_SNAPSHOT_CLEANUP_DRY_RUN=true
41+
OWNERSHIP_SNAPSHOT_TABLE_NAME=creator_ownership_snapshots
42+
```
43+
44+
2. Start the server:
45+
46+
```bash
47+
pnpm dev
48+
```
49+
50+
3. Confirm logs show one of the following:
51+
52+
- `Ownership snapshot cleanup dry-run completed`
53+
- `Ownership snapshot cleanup skipped because target table was not found`
54+
55+
4. Run tests for the scaffold:
56+
57+
```bash
58+
pnpm exec jest src/jobs/ownership-snapshot-cleanup.job.test.ts
59+
```
60+
61+
5. Optional delete validation (only when safe): set `OWNERSHIP_SNAPSHOT_CLEANUP_DRY_RUN=false`, run locally against non-production data, and verify delete counts in logs.

0 commit comments

Comments
 (0)