Skip to content

Commit

Permalink
fix: generate finished event on early return (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagoez authored Oct 31, 2024
1 parent dc16d32 commit aa14306
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions integrationos-archiver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,23 @@ async fn main() -> Result<Unit> {
tracing::error!("Error in archiver: {e}");
});

if let Err(e) = res {
archives
.create_one(&Event::Failed(Failed::new(
e.to_string(),
started.reference(),
started.started_at(),
Utc::now(),
)))
.await?;
}
match res {
Ok(_) => {
archives
.create_one(&Event::Finished(Finished::new(started.reference())))
.await?;
}
Err(e) => {
archives
.create_one(&Event::Failed(Failed::new(
e.to_string(),
started.reference(),
started.started_at(),
Utc::now(),
)))
.await?;
}
};

tracing::info!("Sleeping for {} seconds", config.sleep_after_finish);
tokio::time::sleep(Duration::from_secs(config.sleep_after_finish)).await;
Expand Down Expand Up @@ -124,10 +131,6 @@ async fn dump(
"No events found in collection {}",
target_store.collection.name()
);
// create event Finished
archives
.create_one(&Event::Finished(Finished::new(started.reference())))
.await?;

return Ok(());
}
Expand Down Expand Up @@ -213,6 +216,7 @@ async fn dump(
end_time,
end_time.timestamp_millis()
);

let saved = save(
config,
archives,
Expand Down Expand Up @@ -269,14 +273,12 @@ async fn dump(
for error in &errors {
tracing::error!("Error: {:?}", error);
}
// If we return an error it'll prevent from moving forward in the loop
// return Err(anyhow!("Encountered {} errors during processing", errors.len()));
} else {
tracing::info!("All chunks processed successfully.");
}

archives
.create_one(&Event::Finished(Finished::new(started.reference())))
.await?;

Ok(())
}

Expand Down

0 comments on commit aa14306

Please sign in to comment.