Refactor tracing and type casting in stream-gears
Removed unused tracing initialization and related code from stream-gears. Replaced deprecated `downcast` calls with `cast` for PyO3 types. Cleaned up imports and minor code improvements in biliup-cli and stream-gears modules.
This commit is contained in:
1 parent
3ad7c6ac0f
commit
ff3fd2ef15
4 files changed
+9
-27
No files matched your search
@@ -3,7 +3,6 @@ use crate::server::common::upload::{build_studio, submit_to_bilibili, upload};
|
||||
use crate::server::common::util::Recorder;
|
||||
use crate::server::config::Config;
|
||||
use crate::server::core::download_manager::ActorHandle;
|
||||
use crate::server::core::downloader::Downloader;
|
||||
use crate::server::errors::{AppError, report_to_response};
|
||||
use crate::server::infrastructure::connection_pool::ConnectionPool;
|
||||
use crate::server::infrastructure::context::{Worker, WorkerStatus};
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::server::core::plugin::DownloadPlugin;
|
||||
use crate::server::errors::{AppError, AppResult};
|
||||
use crate::server::infrastructure::context::{Context, Worker, WorkerStatus};
|
||||
use async_channel::{Receiver, Sender};
|
||||
use error_stack::{FutureExt, ResultExt, bail};
|
||||
use error_stack::{ResultExt, bail};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -16,34 +16,18 @@ use biliup::credential::Credential;
|
||||
use biliup::downloader::extractor::CallbackFn;
|
||||
use biliup::downloader::util::{LifecycleFile, Segmentable};
|
||||
use biliup::downloader::{hls, httpflv};
|
||||
use clap::Parser;
|
||||
use pyo3::types::{PyList, PyType};
|
||||
use std::collections::HashMap;
|
||||
use std::env::args;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Mutex, Once};
|
||||
use std::time::Duration;
|
||||
use tracing::{debug, error, info};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
use biliup::client::StatelessClient;
|
||||
use biliup::downloader::flv_parser::header;
|
||||
use biliup::downloader::httpflv::Connection;
|
||||
use pyo3::exceptions::PyRuntimeError;
|
||||
use tracing_appender::rolling::Rotation;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
static INIT: Once = Once::new();
|
||||
// 全局保存 guard,防止被 drop
|
||||
static GUARD: Mutex<Option<tracing_appender::non_blocking::WorkerGuard>> = Mutex::new(None);
|
||||
|
||||
fn init_tracing_with_rotation() {
|
||||
INIT.call_once(|| {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn download_with_hook(
|
||||
@@ -419,7 +403,7 @@ pub fn main_loop(py: Python<'_>) -> PyResult<()> {
|
||||
// 获取 Python 的 sys.argv
|
||||
let sys = py.import("sys")?;
|
||||
let bound = sys.getattr("argv")?;
|
||||
let argv: &Bound<PyList> = bound.downcast()?;
|
||||
let argv: &Bound<PyList> = bound.cast()?;
|
||||
|
||||
let mut args: Vec<String> = argv
|
||||
.iter()
|
||||
@@ -470,7 +454,6 @@ pub fn main_loop(py: Python<'_>) -> PyResult<()> {
|
||||
/// A Python module implemented in Rust.
|
||||
#[pymodule]
|
||||
fn stream_gears(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
init_tracing_with_rotation();
|
||||
// let file_appender = tracing_appender::rolling::daily("", "upload.log");
|
||||
// let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
|
||||
// tracing_subscriber::fmt()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{DanmakuClient, construct_headers, download};
|
||||
use crate::{DanmakuClient, construct_headers};
|
||||
use async_trait::async_trait;
|
||||
use biliup::downloader::util::Segmentable;
|
||||
use biliup::uploader::util::SubmitOption;
|
||||
@@ -21,7 +21,7 @@ use biliup_cli::server::infrastructure::repositories::get_upload_config;
|
||||
use biliup_cli::server::infrastructure::service_register::ServiceRegister;
|
||||
use biliup_cli::uploader::{append, list, login, renew, show, upload_by_command, upload_by_config};
|
||||
use chrono::Utc;
|
||||
use clap::{Error, Parser};
|
||||
use clap::Parser;
|
||||
use error_stack::{Report, ResultExt};
|
||||
use fancy_regex::Regex;
|
||||
use pyo3::prelude::PyDictMethods;
|
||||
@@ -205,12 +205,12 @@ pub fn from_py(actor_handle: Arc<ActorHandle>) -> PyResult<Vec<DownloadManager>>
|
||||
|
||||
// 如果要获取类属性(而不是实例属性)
|
||||
let bound = plugin_class.getattr("download_plugins")?;
|
||||
let plugin_list: &Bound<PyList> = bound.downcast()?;
|
||||
let plugin_list: &Bound<PyList> = bound.cast()?;
|
||||
|
||||
plugin_list
|
||||
.iter()
|
||||
.map(|x| {
|
||||
let download = x.downcast::<PyType>()?;
|
||||
let download = x.cast::<PyType>()?;
|
||||
let py_plugin = PyPlugin::from_pytype(download)?;
|
||||
Ok(DownloadManager::new(py_plugin, actor_handle.clone()))
|
||||
})
|
||||
@@ -318,7 +318,7 @@ impl ConfigState {
|
||||
return Ok(d);
|
||||
}
|
||||
// 尝试转换为字典并过滤
|
||||
return match bound.downcast::<PyDict>() {
|
||||
return match bound.cast::<PyDict>() {
|
||||
Ok(dict) => {
|
||||
let filtered = PyDict::new(py);
|
||||
dict.iter()
|
||||
@@ -382,7 +382,7 @@ pub(crate) async fn _main(args: &[String]) -> AppResult<()> {
|
||||
// 或者按小时滚动
|
||||
// let file_appender = tracing_appender::rolling::hourly("logs", "upload.log");
|
||||
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
let subscriber = tracing_subscriber::registry()
|
||||
.with(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
|
||||
@@ -407,7 +407,7 @@ pub(crate) async fn _main(args: &[String]) -> AppResult<()> {
|
||||
.with_ansi(false), // .json() // 可选:使用 JSON 格式便于解析
|
||||
);
|
||||
|
||||
let _ = subscriber.init();
|
||||
subscriber.init();
|
||||
|
||||
info!("Tracing initialized with daily rotation");
|
||||
|
||||
|
||||
Reference in new issue
Block a user