Skip to content

Commit

Permalink
fix: fav daemon uses data cached in memory instead of reading again…
Browse files Browse the repository at this point in the history
…, leading to repeated pullings with `fav pull` called manually during daemon.
  • Loading branch information
kingwingfly committed Nov 11, 2024
1 parent 29c734f commit cb2bd7b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
-->

## [Unreleased]
## [0.2.36] - 2024-11-12

- fix: `fav daemon` uses data cached in memory instead of reading again,
leading to repeated pullings with `fav pull` called manually during daemon.

## [0.2.35] - 2024-11-10

- enhance: `fav -d /path` to set working directory.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace.package]
version = "0.2.35"
version = "0.2.36"
authors = ["Louis <836250617@qq.com>"]
description = "Back up your favorite online resources with CLI."
license = "MIT"
Expand All @@ -17,7 +17,7 @@ documentation = ""
fav_core = { path = "fav_core", version = "0.1.6" }
fav_derive = { path = "fav_derive", version = "0.0.3" }
fav_utils = { path = "fav_utils", version = "0.0.14" }
fav_cli = { path = "fav_cli", version = "0.2.35" }
fav_cli = { path = "fav_cli", version = "0.2.36" }

[profile.release]
lto = "fat"
Expand Down
8 changes: 6 additions & 2 deletions fav_cli/src/bili/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub(super) async fn pull(sets: &mut BiliSets, ids: Vec<String>) -> FavCoreResult
Ok(())
}

pub(super) async fn daemon(sets: &mut BiliSets, interval: u64) -> FavCoreResult<()> {
pub(super) async fn daemon(interval: u64) -> FavCoreResult<()> {
if interval < 15 {
warn!("Interval would better to be greater than 15 minutes.");
}
Expand All @@ -204,8 +204,12 @@ pub(super) async fn daemon(sets: &mut BiliSets, interval: u64) -> FavCoreResult<
let mut fire: bool = true;
loop {
tokio::select! {
res = pull_all(sets), if fire => {
res = async {
let mut sets = BiliSets::read().unwrap_or_default();
pull_all(&mut sets).await?;
sets.write()?;
FavCoreResult::Ok(())
}, if fire => {
if let Err(e) = res {
error!("{}", e);
}
Expand Down
8 changes: 4 additions & 4 deletions fav_cli/src/bili/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ impl Cli {
let mut cmd = Cli::command();
clap_complete::generate(shell, &mut cmd, "fav", &mut std::io::stdout());
}
Commands::Daemon { interval } => {
check_ffmpeg()?;
daemon(interval).await?;
}
subcmd => {
let mut sets = BiliSets::read().unwrap_or_default();
let res = match subcmd {
Expand Down Expand Up @@ -170,10 +174,6 @@ impl Cli {
None => pull_all(&mut sets).await,
}
}
Commands::Daemon { interval } => {
check_ffmpeg()?;
daemon(&mut sets, interval).await
}
_ => unreachable!(),
};
sets.write()?;
Expand Down

0 comments on commit cb2bd7b

Please sign in to comment.