fixed critical stall bug on first card

This commit is contained in:
Steven 2023-08-04 20:18:05 -04:00
parent aa4559be2a
commit 6cd610e727
3 changed files with 11 additions and 13 deletions

View file

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use reqwest;
use prometheus::{GaugeVec, Opts};
use std::{env, fs::File, fs::OpenOptions, io::BufReader, collections::HashMap};
use prometheus::{GaugeVec, Opts, Registry};
use std::{env, fs::File, fs::OpenOptions, io::BufReader, collections::HashMap,sync::Arc};
use crate::util;
lazy_static::lazy_static! {
@ -88,8 +88,8 @@ pub async fn process_cards(interval: &mut tokio::time::Interval) -> Result<(), B
for card_from_file in &mut cards_data.cards {
process_card(card_from_file).await?;
pb.inc(1);
interval.tick().await;
}
interval.tick().await;
process_export_data(&mut cards_data.cards);
pb.finish_with_message("Completed!");
@ -102,3 +102,9 @@ pub async fn process_cards(interval: &mut tokio::time::Interval) -> Result<(), B
serde_json::to_writer_pretty(file, &cards_data)?;
Ok(())
}
pub fn setup_registry() -> Result<Arc<Registry>, Box<dyn std::error::Error>> {
let registry = Arc::new(Registry::new());
registry.register(Box::new(CARD_VALUES.clone())).unwrap();
Ok(registry)
}

View file

@ -1,8 +1,6 @@
use dotenv;
use tokio::time::Duration;
use prometheus::Registry;
use tracing::info;
use std::sync::Arc;
mod server;
mod cards;
@ -11,7 +9,7 @@ mod handlers;
mod util;
use server::run_server;
use cards::{CARD_VALUES,get_data_update_interval};
use cards::{setup_registry, get_data_update_interval};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -33,9 +31,3 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cards::process_cards(&mut interval).await?;
}
}
fn setup_registry() -> Result<Arc<Registry>, Box<dyn std::error::Error>> {
let registry = Arc::new(Registry::new());
registry.register(Box::new(CARD_VALUES.clone())).unwrap();
Ok(registry)
}

View file

@ -32,7 +32,7 @@ pub fn setup_progress_bar(len: u64) -> ProgressBar {
let style = ProgressStyle::default_bar()
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})")
.unwrap()
.progress_chars("#|.");
.progress_chars("#>.");
pb.set_style(style);
pb
}