fix: update interval setting

This commit is contained in:
Xinrea
2025-10-29 00:16:06 +08:00
parent 4058b425c8
commit b4fb2d058a
7 changed files with 68 additions and 10 deletions

View File

@@ -77,6 +77,8 @@ where
room_info: Arc<RwLock<RoomInfo>>,
/// The user info for the recorder
user_info: Arc<RwLock<UserInfo>>,
/// The update interval for room status
update_interval: Arc<atomic::AtomicU64>,
/// The platform live id for the current recording
platform_live_id: Arc<RwLock<String>>,

View File

@@ -42,6 +42,7 @@ impl BiliRecorder {
account: &Account,
cache_dir: PathBuf,
event_channel: broadcast::Sender<RecorderEvent>,
update_interval: Arc<atomic::AtomicU64>,
enabled: bool,
) -> Result<Self, crate::errors::RecorderError> {
let client = reqwest::Client::new();
@@ -59,6 +60,7 @@ impl BiliRecorder {
cache_dir,
quit: Arc::new(atomic::AtomicBool::new(false)),
enabled: Arc::new(atomic::AtomicBool::new(enabled)),
update_interval,
is_recording: Arc::new(atomic::AtomicBool::new(false)),
room_info: Arc::new(RwLock::new(RoomInfo::default())),
user_info: Arc::new(RwLock::new(UserInfo::default())),
@@ -373,7 +375,10 @@ impl crate::traits::RecorderTrait<BiliExtra> for BiliRecorder {
continue;
}
tokio::time::sleep(Duration::from_secs(15)).await;
tokio::time::sleep(Duration::from_secs(
self_clone.update_interval.load(atomic::Ordering::Relaxed),
))
.await;
}
}));
}

View File

@@ -48,6 +48,7 @@ impl DouyinRecorder {
account: &Account,
cache_dir: PathBuf,
channel: broadcast::Sender<RecorderEvent>,
update_interval: Arc<atomic::AtomicU64>,
enabled: bool,
) -> Result<Self, crate::errors::RecorderError> {
Ok(Self {
@@ -69,6 +70,7 @@ impl DouyinRecorder {
last_sequence: Arc::new(atomic::AtomicU64::new(0)),
danmu_task: Arc::new(Mutex::new(None)),
record_task: Arc::new(Mutex::new(None)),
update_interval,
total_duration: Arc::new(atomic::AtomicU64::new(0)),
total_size: Arc::new(atomic::AtomicU64::new(0)),
extra: DouyinExtra {
@@ -327,7 +329,10 @@ impl crate::traits::RecorderTrait<DouyinExtra> for DouyinRecorder {
continue;
}
tokio::time::sleep(Duration::from_secs(15)).await;
tokio::time::sleep(Duration::from_secs(
self_clone.update_interval.load(atomic::Ordering::Relaxed),
))
.await;
}
log::info!("[{}]Recording thread quit.", self_clone.room_id);
}));

View File

@@ -34,6 +34,7 @@ impl HuyaRecorder {
account: &Account,
cache_dir: PathBuf,
channel: broadcast::Sender<RecorderEvent>,
update_interval: Arc<atomic::AtomicU64>,
enabled: bool,
) -> Result<Self, crate::errors::RecorderError> {
Ok(Self {
@@ -55,6 +56,7 @@ impl HuyaRecorder {
last_sequence: Arc::new(atomic::AtomicU64::new(0)),
danmu_task: Arc::new(Mutex::new(None)),
record_task: Arc::new(Mutex::new(None)),
update_interval,
total_duration: Arc::new(atomic::AtomicU64::new(0)),
total_size: Arc::new(atomic::AtomicU64::new(0)),
extra: HuyaExtra {
@@ -224,7 +226,10 @@ impl crate::traits::RecorderTrait<HuyaExtra> for HuyaRecorder {
continue;
}
tokio::time::sleep(Duration::from_secs(15)).await;
tokio::time::sleep(Duration::from_secs(
self_clone.update_interval.load(atomic::Ordering::Relaxed),
))
.await;
}
log::info!("[{}]Recording thread quit.", self_clone.room_id);
}));

View File

@@ -1,7 +1,8 @@
use std::path::{Path, PathBuf};
use chrono::Local;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use std::sync::atomic::{self, AtomicU64};
use std::sync::Arc;
use crate::{danmu2ass::Danmu2AssOptions, recorder_manager::ClipRangeParams};
@@ -39,6 +40,8 @@ pub struct Config {
pub webhook_url: String,
#[serde(default = "default_danmu_ass_options")]
pub danmu_ass_options: Danmu2AssOptions,
#[serde(skip)]
pub update_interval: Arc<AtomicU64>,
}
#[derive(Deserialize, Serialize, Clone)]
@@ -107,6 +110,7 @@ impl Config {
if let Ok(content) = std::fs::read_to_string(config_path) {
if let Ok(mut config) = toml::from_str::<Config>(&content) {
config.config_path = config_path.to_str().unwrap().into();
config.update_interval = Arc::new(AtomicU64::new(config.status_check_interval));
return Ok(config);
}
}
@@ -137,6 +141,7 @@ impl Config {
whisper_language: default_whisper_language(),
webhook_url: default_webhook_url(),
danmu_ass_options: default_danmu_ass_options(),
update_interval: Arc::new(AtomicU64::new(default_status_check_interval())),
};
config.save();
@@ -220,4 +225,11 @@ impl Config {
Path::new(&output).join(&sanitized)
}
pub fn set_status_check_interval(&mut self, interval: u64) {
self.status_check_interval = interval;
self.update_interval
.store(interval, atomic::Ordering::Relaxed);
self.save();
}
}

View File

@@ -251,8 +251,11 @@ pub async fn update_status_check_interval(
interval = 10; // Minimum interval of 10 seconds
}
log::info!("Updating status check interval to {interval} seconds");
state.config.write().await.status_check_interval = interval;
state.config.write().await.save();
state
.config
.write()
.await
.set_status_check_interval(interval);
Ok(())
}

View File

@@ -497,15 +497,41 @@ impl RecorderManager {
let cache_dir = PathBuf::from(&cache_dir);
let event_tx = self.get_event_sender();
let update_interval = self.config.read().await.update_interval.clone();
let recorder: RecorderType = match platform {
PlatformType::BiliBili => RecorderType::BiliBili(
BiliRecorder::new(room_id, account, cache_dir, event_tx, enabled).await?,
BiliRecorder::new(
room_id,
account,
cache_dir,
event_tx,
update_interval,
enabled,
)
.await?,
),
PlatformType::Douyin => RecorderType::Douyin(
DouyinRecorder::new(room_id, extra, account, cache_dir, event_tx, enabled).await?,
DouyinRecorder::new(
room_id,
extra,
account,
cache_dir,
event_tx,
update_interval,
enabled,
)
.await?,
),
PlatformType::Huya => RecorderType::Huya(
HuyaRecorder::new(room_id, account, cache_dir, event_tx, enabled).await?,
HuyaRecorder::new(
room_id,
account,
cache_dir,
event_tx,
update_interval,
enabled,
)
.await?,
),
_ => {
return Err(RecorderManagerError::InvalidPlatformType {