Skip to content

Commit a3c283f

Browse files
authored
Limit the number of items to notify each time. (#30)
1 parent bb99483 commit a3c283f

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ async fn run<T: Notifier>(source: SourcePtr, mut notifier: T) {
102102
let mut last_update = Local::now();
103103
let interval = source.interval();
104104
let retry_config = ConstantBuilder::default();
105+
let each_notify = notifier.num_items_each_notify();
105106

106107
loop {
107108
tokio::time::sleep(interval).await;
@@ -122,7 +123,13 @@ async fn run<T: Notifier>(source: SourcePtr, mut notifier: T) {
122123
});
123124

124125
// notify
125-
notifier.notify(&source.name(), new_items.clone()).await?;
126+
if each_notify == 0 {
127+
notifier.notify(&source.name(), new_items.clone()).await?;
128+
} else {
129+
for chunk in new_items.chunks(each_notify) {
130+
notifier.notify(&source.name(), chunk.to_vec()).await?;
131+
}
132+
}
126133
}
127134
};
128135

src/notifier/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ use crate::Result;
2424
#[async_trait::async_trait]
2525
pub trait Notifier: Sync + Send + Clone {
2626
async fn notify(&mut self, source: &str, items: Vec<Item>) -> Result<()>;
27+
28+
/// The number of items to be notified each time.
29+
///
30+
/// If it is 0, all items will be notified at once.
31+
fn num_items_each_notify(&self) -> usize {
32+
0
33+
}
2734
}

src/notifier/qq_guild.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ impl Notifier for QQGuildNotifier {
9292
}
9393
Ok(())
9494
}
95+
96+
fn num_items_each_notify(&self) -> usize {
97+
5
98+
}
9599
}
96100

97101
impl QQGuildNotifier {

0 commit comments

Comments
 (0)