functional tracing
This commit is contained in:
@@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration};
|
||||
use async_trait::async_trait;
|
||||
use async_mutex::Mutex;
|
||||
use headless_chrome::{Browser, LaunchOptions};
|
||||
use log::{error, info};
|
||||
use tracing::{error, info, debug, trace, warn};
|
||||
use rocket::{fairing::{Fairing, self}, Rocket, Build, Request, request::{FromRequest, Outcome}, futures::pin_mut, http::Status};
|
||||
use tokio::time::sleep;
|
||||
|
||||
@@ -45,9 +45,11 @@ impl ChromiumCoordinator {
|
||||
|
||||
pub async fn new() -> Self {
|
||||
let instances: Arc<Mutex<Vec<BrowserHolder>>> = Arc::new(Mutex::new(Vec::with_capacity(Self::NUMBER_OF_INSTANCES)));
|
||||
trace!("creating {} Chromium instances", Self::NUMBER_OF_INSTANCES);
|
||||
while instances.lock().await.len() < Self::NUMBER_OF_INSTANCES {
|
||||
instances.lock().await.push(Self::create_browser_instance());
|
||||
}
|
||||
trace!("done creating {} Chromium instances", Self::NUMBER_OF_INSTANCES);
|
||||
|
||||
Self { instances }
|
||||
}
|
||||
@@ -62,9 +64,10 @@ impl ChromiumCoordinator {
|
||||
fn spawn_browser(&self) {
|
||||
let instances = self.instances.clone();
|
||||
tokio::spawn(async move {
|
||||
info!("Spawn new instance of browser");
|
||||
debug!("spawn new instance of browser");
|
||||
// Create new instance
|
||||
instances.lock().await.push(Self::create_browser_instance());
|
||||
debug!("spawned new instance of browser");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,7 +97,10 @@ impl ChromiumCoordinator {
|
||||
let browser = self.loop_get_instance().await;
|
||||
match browser.browser.get_version() {
|
||||
Ok(_) => Ok(browser),
|
||||
Err(_) => Err(()),
|
||||
Err(_) => {
|
||||
warn!("found dead browser instance");
|
||||
Err(())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +109,7 @@ impl ChromiumCoordinator {
|
||||
match self.try_get_browser().await {
|
||||
Ok(browser) => return Ok(browser),
|
||||
Err(_) => {
|
||||
trace!("all instances of browser are dead... waiting for ");
|
||||
// all instances may be dead ... we must wait for new instance
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user