Skip to content

Commit

Permalink
Call control service on readiness error (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 authored Oct 31, 2024
1 parent a5e1d20 commit ad5ae8b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [4.2.0] - 2024-10-31

* Call control service on readiness error

## [4.1.1] - 2024-10-15

* Disconnect on error from service readiness check
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-mqtt"
version = "4.1.1"
version = "4.2.0"
authors = ["ntex contributors <[email protected]>"]
description = "Client and Server framework for MQTT v5 and v3.1.1 protocols"
documentation = "https://docs.rs/ntex-mqtt"
Expand All @@ -18,7 +18,7 @@ features = ["ntex/tokio"]
ntex-io = "2"
ntex-net = "2"
ntex-util = "2"
ntex-service = "3"
ntex-service = "3.2.1"
ntex-bytes = "0.1"
ntex-codec = "0.6"
ntex-router = "0.5"
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub enum MqttError<E> {
/// Publish handler service error
#[error("Service error")]
Service(E),
/// Publish service readiness error
#[error("Service readiness error")]
Readiness(Option<E>),
/// Handshake error
#[error("Mqtt handshake error: {}", _0)]
Handshake(#[from] HandshakeError<E>),
Expand Down
14 changes: 12 additions & 2 deletions src/v3/client/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ where
#[inline]
async fn ready(&self, ctx: ServiceCtx<'_, Self>) -> Result<(), Self::Error> {
let (res1, res2) = join(ctx.ready(&self.publish), ctx.ready(&self.inner.control)).await;
res1.map_err(MqttError::Service)?;
res2
if let Err(e) = res1 {
if res2.is_err() {
Err(MqttError::Readiness(Some(e)))
} else {
match ctx.call_nowait(&self.inner.control, Control::error(e)).await {
Ok(_) => Err(MqttError::Readiness(None)),
Err(err) => Err(err),
}
}
} else {
res2
}
}

async fn shutdown(&self) {
Expand Down
14 changes: 12 additions & 2 deletions src/v3/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,18 @@ where
#[inline]
async fn ready(&self, ctx: ServiceCtx<'_, Self>) -> Result<(), Self::Error> {
let (res1, res2) = join(ctx.ready(&self.publish), ctx.ready(&self.inner.control)).await;
res1.map_err(|e| MqttError::Service(e.into()))?;
res2
if let Err(e) = res1 {
if res2.is_err() {
Err(MqttError::Readiness(Some(e.into())))
} else {
match ctx.call_nowait(&self.inner.control, Control::error(e.into())).await {
Ok(_) => Err(MqttError::Readiness(None)),
Err(err) => Err(err),
}
}
} else {
res2
}
}

async fn shutdown(&self) {
Expand Down
14 changes: 12 additions & 2 deletions src/v5/client/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,18 @@ where
#[inline]
async fn ready(&self, ctx: ServiceCtx<'_, Self>) -> Result<(), Self::Error> {
let (res1, res2) = join(ctx.ready(&self.publish), ctx.ready(&self.inner.control)).await;
res1.map_err(MqttError::Service)?;
res2
if let Err(e) = res1 {
if res2.is_err() {
Err(MqttError::Readiness(Some(e)))
} else {
match ctx.call_nowait(&self.inner.control, Control::error(e)).await {
Ok(_) => Err(MqttError::Readiness(None)),
Err(err) => Err(err),
}
}
} else {
res2
}
}

async fn shutdown(&self) {
Expand Down
14 changes: 12 additions & 2 deletions src/v5/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,18 @@ where
#[inline]
async fn ready(&self, ctx: ServiceCtx<'_, Self>) -> Result<(), Self::Error> {
let (res1, res2) = join(ctx.ready(&self.publish), ctx.ready(&self.inner.control)).await;
res1.map_err(|e| MqttError::Service(e.into()))?;
res2
if let Err(e) = res1 {
if res2.is_err() {
Err(MqttError::Readiness(Some(e.into())))
} else {
match ctx.call_nowait(&self.inner.control, Control::error(e.into())).await {
Ok(_) => Err(MqttError::Readiness(None)),
Err(err) => Err(err),
}
}
} else {
res2
}
}

async fn shutdown(&self) {
Expand Down

0 comments on commit ad5ae8b

Please sign in to comment.