Skip to content

Commit

Permalink
chore: change format again to make the format the same as the connect…
Browse files Browse the repository at this point in the history
…or (#1853)
  • Loading branch information
carneiro-cw authored Nov 7, 2024
1 parent bac44ca commit 87ea414
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/bin/historic_events_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn main() -> Result<(), anyhow::Error> {

let mut hours_since_0 = 0;
let mut event_batch = vec![];
let mut offset = std::fs::read_to_string("last_offset").map(|s| s.trim().parse::<usize>().unwrap()).unwrap_or(0);
for result in iter {
let (number, block) = result.context("failed to read block")?;
let block = block.into_inner();
Expand All @@ -124,13 +125,24 @@ fn main() -> Result<(), anyhow::Error> {

hours_since_0 = timestamp.0 / 3600;
if !event_batch.is_empty() {
let folder_path = format!("events/{}/{:02}/{:02}", date.year(), date.month(), date.day());
let folder_path = format!(
"events/ledger_wallet_events/year={}/month={:02}/day={:02}/hour={:02}",
date.year(),
date.month(),
date.day(),
date.hour()
);
if !std::path::Path::new(&folder_path).exists() {
std::fs::create_dir_all(&folder_path)?;
}
std::fs::write(format!("{}/{:02}", folder_path, date.hour()), event_batch.join("\n"))?;
std::fs::write(
format!("{}/ledger_wallet_events+backfill+{:010}.json", folder_path, offset),
event_batch.join("\n"),
)?;
offset += event_batch.len();
}
std::fs::write("last_processed_block", number.to_string())?;
std::fs::write("last_offset", offset.to_string())?;
event_batch.clear();
}
}
Expand Down

0 comments on commit 87ea414

Please sign in to comment.