Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: log add timestamp and add retry mechanism. #27

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading