Improve snapshot reliability and usability
This commit is contained in:
+18
-7
@@ -176,10 +176,20 @@ async def prune_snapshots(request):
|
||||
max_age_days = data.get("maxAgeDays")
|
||||
if not workflow_key or max_snapshots is None:
|
||||
return web.json_response({"error": "Missing workflowKey or maxSnapshots"}, status=400)
|
||||
max_snapshots = int(max_snapshots)
|
||||
if max_snapshots < 0 or max_snapshots > 10000:
|
||||
raise ValueError("maxSnapshots must be between 0 and 10000")
|
||||
if source not in (None, "node", "regular"):
|
||||
raise ValueError("Invalid prune source")
|
||||
if protected_ids is not None and not isinstance(protected_ids, list):
|
||||
raise ValueError("protectedIds must be an array")
|
||||
max_age_days = int(max_age_days) if max_age_days else None
|
||||
if max_age_days is not None and (max_age_days < 0 or max_age_days > 36500):
|
||||
raise ValueError("maxAgeDays must be between 0 and 36500")
|
||||
deleted = storage.prune(
|
||||
workflow_key, int(max_snapshots),
|
||||
workflow_key, max_snapshots,
|
||||
source=source, protected_ids=protected_ids,
|
||||
max_age_days=int(max_age_days) if max_age_days else None,
|
||||
max_age_days=max_age_days,
|
||||
)
|
||||
return web.json_response({"deleted": deleted})
|
||||
except ValueError as e:
|
||||
@@ -200,12 +210,13 @@ async def migrate_snapshots(request):
|
||||
return web.json_response({"error": "Missing records array"}, status=400)
|
||||
if len(records) > _MAX_MIGRATE_RECORDS:
|
||||
return web.json_response({"error": "Too many records"}, status=413)
|
||||
imported = 0
|
||||
# Validate the entire batch before writing so a bad record cannot leave
|
||||
# a surprising half-imported history.
|
||||
for record in records:
|
||||
if "id" in record and "workflowKey" in record:
|
||||
storage.put(record)
|
||||
imported += 1
|
||||
return web.json_response({"imported": imported})
|
||||
storage.validate_record(record)
|
||||
for record in records:
|
||||
storage.put(record)
|
||||
return web.json_response({"imported": len(records)})
|
||||
except ValueError as e:
|
||||
return web.json_response({"error": str(e)}, status=400)
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user