MCPcopy Create free account
hub / github.com/Tong89/smartNode / snapshot_save

Function snapshot_save

backend/api.py:1268–1295  ·  view source on GitHub ↗

拍摄当前仿真状态快照并保存至内存。 可选 JSON 体:``{"label": "回放点A"}`` 返回快照摘要(不含完整请求列��以减小响应体积)。

()

Source from the content-addressed store, hash-verified

1266@require_role('admin')
1267@rate_limit(20, 60)
1268def snapshot_save():
1269 """拍摄当前仿真状态快照并保存至内存。
1270
1271 可选 JSON 体:``{"label": "回放点A"}``
1272
1273 返回快照摘要(不含完整请求列��以减小响应体积)。
1274 """
1275 body = request.get_json(silent=True) or {}
1276 label = str(body.get("label", ""))[:128]
1277 try:
1278 snap = simulation_engine.snapshot(label=label)
1279 except Exception:
1280 logger.exception("快照保存失败")
1281 return error_response("INTERNAL_ERROR")
1282
1283 global _saved_snapshot
1284 _saved_snapshot = snap
1285
1286 # 响应中仅返回摘要,完整快照可通过 /api/snapshot/export 下载
1287 return ok({
1288 "version": snap["version"],
1289 "saved_at": snap["saved_at"],
1290 "label": snap.get("label", ""),
1291 "current_time": snap["current_time"],
1292 "id_counter": snap.get("id_counter", 0),
1293 "active_request_count": len(snap.get("transmission_requests", [])),
1294 "history_count": len(snap.get("request_history", [])),
1295 })
1296
1297
1298@app.route('/api/snapshot/load', methods=['POST'])

Callers

nothing calls this directly

Calls 4

error_responseFunction · 0.90
okFunction · 0.90
snapshotMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected