diff --git a/src/main.rs b/src/main.rs index d686e7f..e5c6777 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,6 +102,7 @@ async fn run(source: SourcePtr, mut notifier: T) { let mut last_update = Local::now(); let interval = source.interval(); let retry_config = ConstantBuilder::default(); + let each_notify = notifier.num_items_each_notify(); loop { tokio::time::sleep(interval).await; @@ -122,7 +123,13 @@ async fn run(source: SourcePtr, mut notifier: T) { }); // notify - notifier.notify(&source.name(), new_items.clone()).await?; + if each_notify == 0 { + notifier.notify(&source.name(), new_items.clone()).await?; + } else { + for chunk in new_items.chunks(each_notify) { + notifier.notify(&source.name(), chunk.to_vec()).await?; + } + } } }; diff --git a/src/notifier/mod.rs b/src/notifier/mod.rs index 381357c..eb80153 100644 --- a/src/notifier/mod.rs +++ b/src/notifier/mod.rs @@ -24,4 +24,11 @@ use crate::Result; #[async_trait::async_trait] pub trait Notifier: Sync + Send + Clone { async fn notify(&mut self, source: &str, items: Vec) -> Result<()>; + + /// The number of items to be notified each time. + /// + /// If it is 0, all items will be notified at once. + fn num_items_each_notify(&self) -> usize { + 0 + } } diff --git a/src/notifier/qq_guild.rs b/src/notifier/qq_guild.rs index ad8e9e9..66fe57a 100644 --- a/src/notifier/qq_guild.rs +++ b/src/notifier/qq_guild.rs @@ -92,6 +92,10 @@ impl Notifier for QQGuildNotifier { } Ok(()) } + + fn num_items_each_notify(&self) -> usize { + 5 + } } impl QQGuildNotifier {