count processed items only

This commit is contained in:
yggverse 2026-04-07 18:32:55 +03:00
parent d650683079
commit af874ea32b

View file

@ -53,15 +53,21 @@ async fn main() {
items.len(), items.len(),
channel.items_limit 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) { if !channel_item_id_regex.is_match(&item.id) {
panic!( panic!(
"API returned unexpected item ID `{}` for channel `{c}`; unsafe to continue as used in the exec context", "API returned unexpected item ID `{}` for channel `{c}`; unsafe to continue as used in the exec context",
&item.id &item.id
) )
} }
if channel.items_limit.is_some_and(|l| i >= l) { if channel
debug!("items limit for channel `{c}` reached at {i}; break."); .items_limit
.is_some_and(|limit| items_processed >= limit)
{
debug!(
"processed items limit for channel `{c}` reached at {items_processed}; break."
);
break; break;
} }
if channel if channel
@ -134,10 +140,11 @@ async fn main() {
}) { }) {
match database.process(&item.id) { match database.process(&item.id) {
Ok(()) => { Ok(()) => {
items_processed += 1;
info!( info!(
"exec `{cmd}` for channel `{c}` successful." "exec `{cmd}` for channel `{c}` successful."
); );
debug!("stdout: `{response:?}`"); debug!("stdout: `{response:?}`")
} }
Err(e) => panic!( Err(e) => panic!(
"can't persist processed item `{}` for channel `{c}` by `{cmd}`: `{e}`", "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)) .all(|s| String::from_utf8_lossy(&response.stdout).contains(s))
}) { }) {
info!("exec `{}` successful.", command.exec); info!("exec `{}` successful.", command.exec);
debug!("stdout: `{response:?}`"); debug!("stdout: `{response:?}`")
} else { } else {
panic!("unexpected exec result `{}`: `{response:?}`", command.exec) panic!("unexpected exec result `{}`: `{response:?}`", command.exec)
} }