From af874ea32b036c952dbf6a53c0abb6548bd5531a Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 7 Apr 2026 18:32:55 +0300 Subject: [PATCH] count processed items only --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index f94beb5..4fe660c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,15 +53,21 @@ async fn main() { items.len(), channel.items_limit ); - for (i, item) in items.into_iter().enumerate() { + let mut items_processed = 0; // items that match config conditions only + for item in items { if !channel_item_id_regex.is_match(&item.id) { panic!( "API returned unexpected item ID `{}` for channel `{c}`; unsafe to continue as used in the exec context", &item.id ) } - if channel.items_limit.is_some_and(|l| i >= l) { - debug!("items limit for channel `{c}` reached at {i}; break."); + if channel + .items_limit + .is_some_and(|limit| items_processed >= limit) + { + debug!( + "processed items limit for channel `{c}` reached at {items_processed}; break." + ); break; } if channel @@ -134,10 +140,11 @@ async fn main() { }) { match database.process(&item.id) { Ok(()) => { + items_processed += 1; info!( "exec `{cmd}` for channel `{c}` successful." ); - debug!("stdout: `{response:?}`"); + debug!("stdout: `{response:?}`") } Err(e) => panic!( "can't persist processed item `{}` for channel `{c}` by `{cmd}`: `{e}`", @@ -198,7 +205,7 @@ fn cmd(command: &config::Command) { .all(|s| String::from_utf8_lossy(&response.stdout).contains(s)) }) { info!("exec `{}` successful.", command.exec); - debug!("stdout: `{response:?}`"); + debug!("stdout: `{response:?}`") } else { panic!("unexpected exec result `{}`: `{response:?}`", command.exec) }