diff --git a/uplc/src/plc.rs b/uplc/src/plc.rs index 6e67e91..4df22b8 100644 --- a/uplc/src/plc.rs +++ b/uplc/src/plc.rs @@ -1,7 +1,7 @@ use crate::db::{DB, OperationLogEntry}; use color_eyre::eyre::{Result, eyre}; use serde::Deserialize; -use std::collections::HashMap; +use std::{collections::HashMap, time::Duration}; #[derive(Debug, Deserialize)] pub struct CreateOpV1 { @@ -71,6 +71,7 @@ impl From for OperationLogEntry { const USER_AGENT: &str = "change-me (+https://willow.sh)"; +// todo look at switching to websocket after backfilled pub async fn run_plc_sync(db: DB) -> Result<()> { let client = reqwest::Client::builder().user_agent(USER_AGENT).build()?; @@ -100,18 +101,23 @@ pub async fn run_plc_sync(db: DB) -> Result<()> { .into() }) .collect::>(); + let count = ops.len(); - if ops.is_empty() { - println!("no records returned, done!"); - break; + if count == 0 { + println!("no ops returned, sleeping for 30 seconds"); + tokio::time::sleep(Duration::from_secs(30)).await; + continue; } println!(" found {} records", ops.len()); after = ops.last().unwrap().seq; - total += ops.len(); + total += count; db.upsert_operations(ops)?; - } - Ok(()) + if count < 200 { + println!("only returned {} ops, sleeping for 10 seconds", count); + tokio::time::sleep(Duration::from_secs(10)).await; + } + } }