From 85943861ea66ee5eaf40aa2c405892636b59ce71 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 22 Aug 2024 20:21:27 +0200 Subject: fix(update): Propagate the logging options to the `update_raw.py` script --- src/update/mod.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/update/mod.rs') diff --git a/src/update/mod.rs b/src/update/mod.rs index d96e3d1..c913195 100644 --- a/src/update/mod.rs +++ b/src/update/mod.rs @@ -12,7 +12,7 @@ use std::{collections::HashMap, process::Stdio, str::FromStr}; use anyhow::{Context, Ok, Result}; use chrono::{DateTime, Utc}; -use log::{error, info, warn}; +use log::{debug, error, info, warn}; use tokio::{ io::{AsyncBufReadExt, BufReader}, process::Command, @@ -35,10 +35,18 @@ pub async fn update( app: &App, max_backlog: u32, subs_to_update: Vec, - _concurrent_processes: usize, + verbosity: u8, ) -> Result<()> { let subscriptions = get_subscriptions(&app).await?; let mut back_subs: HashMap = HashMap::new(); + let logging = verbosity > 0; + let log_level = match verbosity { + // 0 => 50, // logging.CRITICAL + 0 => 40, // logging.ERROR + 1 => 30, // logging.WARNING + 2 => 20, // logging.INFO + 3.. => 10, // logging.DEBUG + }; let mut urls: Vec = vec![]; for (name, sub) in subscriptions.0 { @@ -60,10 +68,15 @@ pub async fn update( let mut child = Command::new("raw_update.py") .arg(max_backlog.to_string()) .arg(urls.len().to_string()) + .arg(log_level.to_string()) .args(&urls) .args(&hashes.iter().map(|haz| haz.to_string()).collect::>()) .stdout(Stdio::piped()) - .stderr(Stdio::null()) + .stderr(if logging { + Stdio::inherit() + } else { + Stdio::null() + }) .stdin(Stdio::null()) .spawn() .context("Failed to call python3 update_raw")?; @@ -95,7 +108,12 @@ pub async fn update( let out = child.wait().await?; if !out.success() { - error!("The update_raw.py invokation failed for all subscriptions.") + error!( + "The update_raw.py invokation failed (exit code: {}).", + out.code() + .map(|f| f.to_string()) + .unwrap_or("".to_owned()) + ) } Ok(()) -- cgit 1.4.1