Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify consumer checking logic #1033

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions async-nats/src/jetstream/consumer/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,27 +469,33 @@ impl Consumer<OrderedConfig> {
async move {
loop {
let current_state = state.borrow().to_owned();
tokio::select! {
_ = context.client.state.changed() => {
if state.borrow().to_owned() != State::Connected || current_state == State::Connected {
continue;

match tokio::time::timeout(
Duration::from_secs(5),
context.client.state.changed(),
)
.await
{
Ok(_) => {
// State change notification received within the timeout
if state.borrow().to_owned() != State::Connected
|| current_state == State::Connected
{
continue;
}
debug!("reconnected. trigger consumer recreation");
},
_ = tokio::time::sleep(Duration::from_secs(5)) => {
}
Err(_) => {
debug!("heartbeat check");

if !last_seen
.lock()
.unwrap()
.elapsed()
.gt(&Duration::from_secs(10)) {
trace!("last seen ok. wait");
continue;
}
if last_seen.lock().unwrap().elapsed() <= Duration::from_secs(10) {
trace!("last seen ok. wait");
continue;
}
debug!("last seen not ok");
}
}

debug!(
"idle heartbeats expired. recreating consumer s: {}, {:?}",
stream_name, config
Expand Down
Loading