From 008dfd750d866cc8030b0db2867eff68982983bf Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Tue, 24 Mar 2026 03:23:06 +0300 Subject: [PATCH] [api] separate the cursor delete endpoint --- README.md | 13 +++++++------ src/api/crawler.rs | 18 ++++++++++++++++++ src/api/db.rs | 31 +------------------------------ src/api/firehose.rs | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index d50b13c..51dedd2 100644 --- a/README.md +++ b/README.md @@ -215,9 +215,12 @@ each set field accepts one of two forms: (`persisted: false`), only the running task is stopped, the source will reappear on the next restart since `CRAWLER_URLS` is re-applied at startup. (unless you remove it manually from your configuration of course). - - cursor state is not cleared. use `DELETE /cursors` separately if you want + - cursor state is not cleared. use `DELETE /crawler/cursors` separately if you want the source to restart from the beginning when re-added. - returns `200 OK` if the source was found and removed, `404 Not Found` otherwise. +- `DELETE /crawler/cursors`: reset stored cursors for a given crawler URL. body: `{ "key": "..." }` + where key is a URL. clears the relay crawler cursor as well as any by-collection + cursors associated with that URL. causes the next crawler pass to restart from the beginning. ### firehose management @@ -242,9 +245,11 @@ each set field accepts one of two forms: the database and will not reappear on restart. if it came from `RELAY_HOSTS` (`persisted: false`), only the running task is stopped; the source reappears on the next restart. - - cursor state is not cleared. use `DELETE /cursors` separately if you want + - cursor state is not cleared. use `DELETE /firehose/cursors` separately if you want the relay to restart from the beginning when re-added. - returns `200 OK` if the relay was found and removed, `404 Not Found` otherwise. +- `DELETE /firehose/cursors`: reset the stored cursor for a given firehose relay URL. body: `{ "key": "..." }` + where key is a URL. causes the next firehose connection to restart from the beginning. ### repository management @@ -269,10 +274,6 @@ each set field accepts one of two forms: - `POST /db/compact`: trigger a full major compaction of all database keyspaces in parallel. the crawler, firehose, and backfill worker are paused for the duration and restored on completion. -- `DELETE /cursors`: reset all stored cursors for a given URL. body: `{ "key": "..." }` - where key is a URL. clears both the firehose cursor and the relay crawler cursor, - as well as any by-collection cursors associated with that URL. causes the next - firehose connection and crawler pass to restart from the beginning. ## data access (xrpc) diff --git a/src/api/crawler.rs b/src/api/crawler.rs index 18bdbae..63283af 100644 --- a/src/api/crawler.rs +++ b/src/api/crawler.rs @@ -15,6 +15,7 @@ pub fn router() -> Router { .route("/crawler/sources", get(list_sources)) .route("/crawler/sources", post(add_source)) .route("/crawler/sources", delete(remove_source)) + .route("/crawler/cursors", delete(reset_cursor)) } pub async fn list_sources(State(hydrant): State) -> Json> { @@ -62,3 +63,20 @@ pub async fn remove_source( }) .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) } + +#[derive(Deserialize)] +pub struct ResetCursorBody { + pub key: String, +} + +pub async fn reset_cursor( + State(hydrant): State, + Json(body): Json, +) -> Result { + hydrant + .crawler + .reset_cursor(&body.key) + .await + .map(|_| StatusCode::OK) + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) +} diff --git a/src/api/db.rs b/src/api/db.rs index b1d2c9d..f0b2dfb 100644 --- a/src/api/db.rs +++ b/src/api/db.rs @@ -1,17 +1,10 @@ use crate::control::Hydrant; -use axum::{ - Json, Router, - extract::State, - http::StatusCode, - routing::{delete, post}, -}; -use serde::Deserialize; +use axum::{Router, extract::State, http::StatusCode, routing::post}; pub fn router() -> Router { Router::new() .route("/db/train", post(handle_train_dict)) .route("/db/compact", post(handle_compact)) - .route("/cursors", delete(handle_reset_cursor)) } pub async fn handle_train_dict( @@ -25,28 +18,6 @@ pub async fn handle_train_dict( Ok(StatusCode::OK) } -#[derive(Deserialize)] -pub struct ResetCursorBody { - pub key: String, -} - -pub async fn handle_reset_cursor( - State(hydrant): State, - Json(body): Json, -) -> Result { - hydrant - .crawler - .reset_cursor(&body.key) - .await - .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; - hydrant - .firehose - .reset_cursor(&body.key) - .await - .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; - Ok(StatusCode::OK) -} - pub async fn handle_compact( State(hydrant): State, ) -> Result { diff --git a/src/api/firehose.rs b/src/api/firehose.rs index 7a16eca..9ac791a 100644 --- a/src/api/firehose.rs +++ b/src/api/firehose.rs @@ -14,6 +14,7 @@ pub fn router() -> Router { .route("/firehose/sources", get(list_sources)) .route("/firehose/sources", post(add_source)) .route("/firehose/sources", delete(remove_source)) + .route("/firehose/cursors", delete(reset_cursor)) } pub async fn list_sources(State(hydrant): State) -> Json> { @@ -57,3 +58,20 @@ pub async fn remove_source( }) .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) } + +#[derive(Deserialize)] +pub struct ResetCursorBody { + pub key: String, +} + +pub async fn reset_cursor( + State(hydrant): State, + Json(body): Json, +) -> Result { + hydrant + .firehose + .reset_cursor(&body.key) + .await + .map(|_| StatusCode::OK) + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) +} -- knotmirror 0.0.1