Skip to content

Commit

Permalink
feat: correctly wait for blaze startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Threated committed Nov 4, 2024
1 parent e5b3764 commit dedd297
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ impl Project {

#[tokio::main]
async fn main() -> anyhow::Result<()> {
println!("Loading Patient-Project-Indentificator...");
sleep(Duration::from_secs(120)).await;
println!("Starting Patient-Project-Indentificator...");

//Use normal client in prod
Expand Down Expand Up @@ -64,6 +62,12 @@ async fn main() -> anyhow::Result<()> {
),
];

let fhir_client = reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(true) // Mainzelliste returns full server url, some sites do not have a SSL Cert for their servers
.build()?;

wait_for_fhir_server(&fhir_client).await;

let session_id = ma_session(&mainzel_client).await?;

for project in projects {
Expand All @@ -82,10 +86,6 @@ async fn main() -> anyhow::Result<()> {
continue;
};

let fhir_client = reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(true) // Mainzelliste returns full server url, some sites do not have a SSL Cert for their servers
.build()?;

for patient in &patients {
let fhir_patient =
get_patient_from_fhir_server(&fhir_client, patient.to_string()).await;
Expand Down Expand Up @@ -247,3 +247,13 @@ async fn post_patient_to_fhir_server(client: &Client, patient: Resource) -> anyh
.error_for_status()?;
Ok(())
}

async fn wait_for_fhir_server(client: &Client) {
loop {
if client.get(CONFIG.fhir_server_url.join("/fhir/metadata").unwrap()).send().await.is_ok_and(|r| r.status().is_success()) {
break
}
println!("Waiting for fhir server startup");
sleep(Duration::from_secs(10)).await;
}
}

0 comments on commit dedd297

Please sign in to comment.