File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff 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+
14241445Parameter interaction rules:
14251446
14261447- ` retain_last_n ` snapshots are always kept (plus protected refs)
You can’t perform that action at this time.
0 commit comments