You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to have a stream constantly running to have a bot just do simple stuff.
Here is some code (removed some uninteresting parts).
It seems my current patched up together loop is doing it's job and retrying 10 times, I could remove the stop to let it retry infinitely I guess.
I managed to get some logging info as you suggested to investigate why the stream is being killed.
async fn main() -> Result<()> {
femme::with_level(log::LevelFilter::Info);
let args: Vec<String> = env::args().collect();
let mastodata: &String = &args[1];
let mut count = 0u32;
loop {
match run(mastodata).await {
Ok(_) => {
println!("run fn returned OK");
}
Err(e) => {
println!("{:?}", e);
}
};
count += 1;
if count == 10 {
println!("Retried {count} times, I had enough!");
break;
}
}
Ok(())
}
async fn run(mastodata: &String) -> Result<()> {
let mastodon = if let Ok(data) = toml::from_file(mastodata) {
Mastodon::from(data)
} else {
register(mastodata).await?
};
let stream = mastodon.stream_notifications().await?;
info!(
"watching mastodon for notifications. This will run forever, press Ctrl+C to kill the program."
);
stream
.try_for_each(|(event, mastodon)| async move {
if let Event::Notification(notif) = event {
notif_handler(notif, mastodon).await?;
}
Ok(())
})
.await?;
Ok(())
}
Just an exert of the output of one iteration
...
Io(Custom { kind: BrokenPipe, error: "reqwest::Error { kind: Body, source: hyper::Error(Body, Custom {
kind: UnexpectedEof, error: \"unexpected EOF during chunk size line\" }) }" })
{"level":30,"time":1677657167742,"msg":"watching mastodon for notifications. This will run forever, pre
ss Ctrl+C to kill the program."}
{"level":50,"time":1677657792834,"msg":"error reading stream","err":"reqwest::Error { kind: Body, sourc
e: hyper::Error(Body, Custom { kind: UnexpectedEof, error: \"unexpected EOF during chunk size line\" })
}"}
...
I'd be grateful for any suggestion on handling the retries and better managing the potential errors.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I'm trying to have a stream constantly running to have a bot just do simple stuff.
Here is some code (removed some uninteresting parts).
It seems my current patched up together loop is doing it's job and retrying 10 times, I could remove the stop to let it retry infinitely I guess.
I managed to get some logging info as you suggested to investigate why the stream is being killed.
Just an exert of the output of one iteration
I'd be grateful for any suggestion on handling the retries and better managing the potential errors.
I've stumbled upon this stackoverflow discussion but I'm not sure this really applies here.
Beta Was this translation helpful? Give feedback.
All reactions