feat: 添加部分简单 API,相应修改程序入口的初始化流程 (#251)
This commit is contained in:
@@ -3,6 +3,7 @@ pub mod filenamify;
|
||||
pub mod format_arg;
|
||||
pub mod model;
|
||||
pub mod nfo;
|
||||
pub mod signal;
|
||||
pub mod status;
|
||||
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
21
crates/bili_sync/src/utils/signal.rs
Normal file
21
crates/bili_sync/src/utils/signal.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::io;
|
||||
|
||||
use tokio::signal;
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
pub async fn terminate() -> io::Result<()> {
|
||||
signal::ctrl_c().await
|
||||
}
|
||||
|
||||
/// ctrl + c 发送的是 SIGINT 信号,docker stop 发送的是 SIGTERM 信号,都需要处理
|
||||
#[cfg(target_family = "unix")]
|
||||
pub async fn terminate() -> io::Result<()> {
|
||||
use tokio::select;
|
||||
|
||||
let mut term = signal::unix::signal(signal::unix::SignalKind::terminate())?;
|
||||
let mut int = signal::unix::signal(signal::unix::SignalKind::interrupt())?;
|
||||
select! {
|
||||
_ = term.recv() => Ok(()),
|
||||
_ = int.recv() => Ok(()),
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use anyhow::Result;
|
||||
|
||||
static STATUS_MAX_RETRY: u32 = 0b100;
|
||||
static STATUS_OK: u32 = 0b111;
|
||||
pub(super) static STATUS_MAX_RETRY: u32 = 0b100;
|
||||
pub(super) static STATUS_OK: u32 = 0b111;
|
||||
pub static STATUS_COMPLETED: u32 = 1 << 31;
|
||||
|
||||
/// 用来表示下载的状态,不想写太多列了,所以仅使用一个 u32 表示。
|
||||
|
||||
Reference in New Issue
Block a user