Skip to content

Commit 2c6eb0b

Browse files
committed
feat: add context manager examples for snapshot expiration with retention policies
1 parent a1a126f commit 2c6eb0b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

mkdocs/docs/api.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,27 @@ table.maintenance.expire_snapshots().with_retention_policy(
14211421
).commit()
14221422
```
14231423

1424+
##### Using a context manager
1425+
1426+
You can use a context manager to automatically commit on successful exit (and skip commit if an exception occurs):
1427+
1428+
```python
1429+
# Keep the 3 newest snapshots (plus protected refs) and enforce a floor of 8 total
1430+
with table.maintenance.expire_snapshots() as expire:
1431+
expire.with_retention_policy(retain_last_n=3, min_snapshots_to_keep=8)
1432+
1433+
# Only keep the last 5 snapshots
1434+
with table.maintenance.expire_snapshots() as expire:
1435+
expire.retain_last_n(5)
1436+
1437+
# Combine explicit cutoff with other guards
1438+
from datetime import datetime, timedelta
1439+
cutoff = int((datetime.utcnow() - timedelta(days=14)).timestamp() * 1000)
1440+
1441+
with table.maintenance.expire_snapshots() as expire:
1442+
expire.older_than_with_retention(timestamp_ms=cutoff, retain_last_n=2, min_snapshots_to_keep=6)
1443+
```
1444+
14241445
Parameter interaction rules:
14251446

14261447
- `retain_last_n` snapshots are always kept (plus protected refs)

0 commit comments

Comments
 (0)