some observability
This commit is contained in:
parent
8366a1d82e
commit
5115265592
@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration};
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use async_mutex::Mutex;
|
use async_mutex::Mutex;
|
||||||
use headless_chrome::{Browser, LaunchOptions};
|
use headless_chrome::{Browser, LaunchOptions};
|
||||||
use tracing::{error, info, debug, trace, warn, trace_span};
|
use tracing::{error, info, debug, trace, warn, trace_span, info_span};
|
||||||
use rocket::{fairing::{Fairing, self}, Rocket, Build, Request, request::{FromRequest, Outcome}, futures::pin_mut, http::Status};
|
use rocket::{fairing::{Fairing, self}, Rocket, Build, Request, request::{FromRequest, Outcome}, futures::pin_mut, http::Status};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
@ -107,11 +107,14 @@ impl ChromiumCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_browser(&self) -> std::result::Result<BrowserHolder, ()> {
|
pub async fn get_browser(&self) -> std::result::Result<BrowserHolder, ()> {
|
||||||
|
let span = info_span!("get_browser");
|
||||||
|
let _enter = span.enter();
|
||||||
loop {
|
loop {
|
||||||
|
info!("trying to get a browser instance");
|
||||||
match self.try_get_browser().await {
|
match self.try_get_browser().await {
|
||||||
Ok(browser) => return Ok(browser),
|
Ok(browser) => return Ok(browser),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
trace!("all instances of browser are dead... waiting for ");
|
warn!("all instances of browser are dead... waiting for new instance");
|
||||||
// all instances may be dead ... we must wait for new instance
|
// all instances may be dead ... we must wait for new instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
|
use nanobyte_opentelemetry::{default_filter_layer, LogLevel};
|
||||||
use ovlach_pdf::rocket_builder;
|
use ovlach_pdf::rocket_builder;
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let _opentelemetry = nanobyte_opentelemetry::init_telemetry(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
let _opentelemetry = nanobyte_opentelemetry::init_telemetry(
|
||||||
|
env!("CARGO_PKG_NAME"),
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
Some(default_filter_layer(LogLevel::Normal))
|
||||||
|
);
|
||||||
let _ = rocket_builder().launch().await;
|
let _ = rocket_builder().launch().await;
|
||||||
}
|
}
|
@ -42,7 +42,7 @@ fn generate_pdf(browser: Browser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/cv/<username>/pdf")]
|
#[get("/cv/<username>/pdf")]
|
||||||
pub async fn render_pdf_cv(username: &str, browser: BrowserHolder, tracing: TracingSpan) -> NamedFile {
|
pub async fn render_pdf_cv(username: &str, browser: BrowserHolder, tracing: TracingSpan) -> Option<NamedFile> {
|
||||||
let entered_span = tracing.0.enter();
|
let entered_span = tracing.0.enter();
|
||||||
let span = info_span!("render_pdf", username = username);
|
let span = info_span!("render_pdf", username = username);
|
||||||
info!("generate PDF");
|
info!("generate PDF");
|
||||||
@ -51,5 +51,5 @@ pub async fn render_pdf_cv(username: &str, browser: BrowserHolder, tracing: Trac
|
|||||||
});
|
});
|
||||||
info!("done generating");
|
info!("done generating");
|
||||||
drop(entered_span);
|
drop(entered_span);
|
||||||
NamedFile::open("/tmp/foo.pdf").await.expect("failed to open foo.pdf")
|
Some(NamedFile::open("/tmp/foo.pdf").await.expect("failed to open foo.pdf"))
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user