Skip to content

Commit

Permalink
chore: log add timestamp and add retry mechanism. (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
RinChanNOWWW authored Nov 3, 2023
1 parent d6c5409 commit 1de2dda
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
54 changes: 49 additions & 5 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ doctest = false
[dependencies]
anyhow = "1.0"
async-trait = "0.1.68"
backon = "0.4"
chrono = "0.4.22"
clap = { version = "3.2.22", features = ["derive", "env"] }
daemonize = "0.5.0"
futures = "0.3.28"
log = "0.4"
pretty_env_logger = "0.4"
reqwest = { version = "0.11", features = ["json"] }
rss = { version = "2.0" }
sensible-env-logger = { version = "0.3", features = ["local-time"] }
serde = { version = "1.0.145", features = ["derive"] }
serfig = "0.0.2"
tokio = { version = "1.28.0", features = ["rt-multi-thread", "macros"] }
Expand Down
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::fs::File;
use std::path::PathBuf;
use std::sync::Arc;

use backon::ConstantBuilder;
use backon::Retryable;
use blooming::notifier;
use blooming::source::register;
use blooming::source::SourceFactory;
Expand Down Expand Up @@ -71,12 +73,14 @@ async fn run(source: SourcePtr, notifier: Arc<QQNotifier>) {

let mut last_update = Local::now();
let interval = source.interval();
let retry_config = ConstantBuilder::default();

loop {
tokio::time::sleep(interval).await;

let result: Result<()> = try {
let items = source.pull_items().await?;
let fetch = || async { source.pull_items().await };
let items = fetch.retry(&retry_config).await?;
let new_items = items
.into_iter()
.filter(|item| item.pub_date > last_update)
Expand All @@ -90,7 +94,8 @@ async fn run(source: SourcePtr, notifier: Arc<QQNotifier>) {
});

// notify by qq bot
notifier.notify(&source.name(), new_items).await?;
let note = || async { notifier.notify(&source.name(), new_items.clone()).await };
note.retry(&retry_config).await?;
}
};

Expand All @@ -102,7 +107,7 @@ async fn run(source: SourcePtr, notifier: Arc<QQNotifier>) {

#[tokio::main]
async fn main() -> Result<()> {
pretty_env_logger::init();
sensible_env_logger::init_timed_local!();

let args = ClapConfig::parse();

Expand Down

0 comments on commit 1de2dda

Please sign in to comment.