Created
January 23, 2023 10:50
-
-
Save Enigo/9f9781d0bc85d7e35aefe8c55c40c76a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
#[tokio::main] | |
pub async fn read() { | |
let pool = db_handler::open_connection().await; | |
let mut cursor = None; | |
loop { | |
cursor = execute_and_get_cursor(cursor, &pool).await; | |
if cursor.is_none() { | |
break; | |
} else { | |
info!("Current cursor: {}", cursor.clone().unwrap()); | |
} | |
} | |
db_handler::close_connection(pool).await; | |
} | |
async fn execute_and_get_cursor(cursor: Option<String>, pool: &Pool<Postgres>) -> Option<String> { | |
let url = if cursor.is_some() { MINTS_URL.to_owned() + "&cursor=" + cursor.unwrap().as_str() } else { String::from(MINTS_URL) }; | |
let response = fetch_api_response::<Mint>(url.as_str()).await; | |
match response { | |
Ok(mint) => { | |
info!("Processing mint response"); | |
if !mint.result.is_empty() { | |
db_handler::save_mints(mint.result, pool).await; | |
} | |
if !mint.cursor.is_empty() { | |
return Some(mint.cursor); | |
} | |
None | |
} | |
... | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment