MCPcopy Create free account
hub / github.com/acking-you/static_flow / admin_cleanup_api_behavior

Function admin_cleanup_api_behavior

crates/backend/src/handlers.rs:1629–1668  ·  view source on GitHub ↗
(
    State(state): State<AppState>,
    headers: HeaderMap,
    Json(request): Json<AdminApiBehaviorCleanupRequest>,
)

Source from the content-addressed store, hash-verified

1627}
1628
1629pub async fn admin_cleanup_api_behavior(
1630 State(state): State<AppState>,
1631 headers: HeaderMap,
1632 Json(request): Json<AdminApiBehaviorCleanupRequest>,
1633) -> Result<Json<AdminApiBehaviorCleanupResponse>, (StatusCode, Json<ErrorResponse>)> {
1634 ensure_admin_access(&state, &headers)?;
1635 let config = state.api_behavior_runtime_config.read().clone();
1636 let retention_days = request.retention_days.unwrap_or(config.retention_days);
1637 if retention_days <= 0 || retention_days > MAX_CONFIGURABLE_API_BEHAVIOR_RETENTION_DAYS {
1638 return Err(bad_request(
1639 "`retention_days` must be between 1 and 3650 for api behavior cleanup",
1640 ));
1641 }
1642
1643 let before_ms = chrono::Utc::now().timestamp_millis() - retention_days * 24 * 60 * 60 * 1000;
1644 let deleted = state
1645 .store
1646 .cleanup_api_behavior_before(before_ms)
1647 .await
1648 .map_err(|e| internal_error("Failed to cleanup api behavior events", e))?;
1649
1650 if deleted > 0 {
1651 let action = state
1652 .store
1653 .compact_api_behavior_table()
1654 .await
1655 .map_err(|e| internal_error("Failed to compact api behavior events", e))?;
1656 tracing::info!(
1657 action = action.as_str(),
1658 deleted_events = deleted,
1659 "Compacted api_behavior_events after cleanup"
1660 );
1661 }
1662
1663 Ok(Json(AdminApiBehaviorCleanupResponse {
1664 deleted_events: deleted,
1665 before_ms,
1666 retention_days,
1667 }))
1668}
1669
1670pub async fn admin_compact_api_behavior(
1671 State(state): State<AppState>,

Callers

nothing calls this directly

Calls 6

cloneMethod · 0.80
ensure_admin_accessFunction · 0.70
bad_requestFunction · 0.70
internal_errorFunction · 0.70

Tested by

no test coverage detected