Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firehose: Add command line flag for firehose cursor #15

Open
rudyfraser opened this issue Sep 12, 2024 · 0 comments
Open

Firehose: Add command line flag for firehose cursor #15

rudyfraser opened this issue Sep 12, 2024 · 0 comments

Comments

@rudyfraser
Copy link
Member

Right now the firehose always starts at the current stream but in situations where you want to catch up/backfill records you'd need to manually change the code to add a cursor parameter like so:

#[tokio::main]
async fn main() {
    match dotenvy::dotenv() {
        _ => (),
    };

    let default_subscriber_path =
        env::var("FEEDGEN_SUBSCRIPTION_ENDPOINT").unwrap_or("wss://bsky.social".into());
    let client = reqwest::Client::new();
    loop {
        match tokio_tungstenite::connect_async(
            Url::parse(
                format!(
                    "{}/xrpc/com.atproto.sync.subscribeRepos?cursor=1670190430", // Hardcoded cursor. Should be a command line flag.
                    default_subscriber_path
                )
                .as_str(),
            )
            .unwrap(),
        )
        .await
        {
            Ok((mut socket, _response)) => {
                println!("Connected to {default_subscriber_path:?}.");
                while let Some(Ok(Message::Binary(message))) = socket.next().await {
                    let client = client.clone();
                    tokio::spawn(async move {
                        process(message, &client).await;
                    });
                    thread::sleep(Duration::from_millis(8)); // Artificial delay that may be needed when backfilling records due to related issue
                }
            }
            Err(error) => {
                eprintln!("Error connecting to {default_subscriber_path:?}. Waiting to reconnect: {error:?}");
                thread::sleep(Duration::from_millis(500));
                continue;
            }
        }
    }
}

Instead of hardcoding a cursor param you should be able to use an optional command line flag. If there's no flag, it should default to not including a cursor param.

@rudyfraser rudyfraser changed the title Add command line flag for firehose cursor Firehose: Add command line flag for firehose cursor Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant