about summary refs log tree commit diff stats
path: root/src/update/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/update/mod.rs26
1 files changed, 22 insertions, 4 deletions
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<String>,
-    _concurrent_processes: usize,
+    verbosity: u8,
 ) -> Result<()> {
     let subscriptions = get_subscriptions(&app).await?;
     let mut back_subs: HashMap<Url, Subscription> = 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<String> = 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::<Vec<_>>())
         .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("<No exit code>".to_owned())
+        )
     }
 
     Ok(())