@@ -19,6 +19,7 @@ use trogon_nats::jetstream::{
1919 ClaimCheckPublisher , JetStreamContext , JetStreamPublisher , ObjectStorePut , PublishOutcome ,
2020} ;
2121use trogon_nats:: { NatsToken , RequestClient } ;
22+ use trogon_std:: NonZeroDuration ;
2223
2324fn outcome_to_status < E : fmt:: Display > ( outcome : PublishOutcome < E > ) -> StatusCode {
2425 if outcome. is_ok ( ) {
@@ -35,15 +36,15 @@ async fn publish_unroutable<P: JetStreamPublisher, S: ObjectStorePut>(
3536 subject_prefix : & str ,
3637 reason : & str ,
3738 body : Bytes ,
38- ack_timeout : Duration ,
39+ ack_timeout : NonZeroDuration ,
3940) {
4041 let subject = format ! ( "{subject_prefix}.unroutable" ) ;
4142 let mut headers = async_nats:: HeaderMap :: new ( ) ;
4243 headers. insert ( NATS_HEADER_REJECT_REASON , reason) ;
4344 headers. insert ( NATS_HEADER_PAYLOAD_KIND , "unroutable" ) ;
4445
4546 let outcome = publisher
46- . publish_event ( subject, headers, body, ack_timeout)
47+ . publish_event ( subject, headers, body, ack_timeout. into ( ) )
4748 . await ;
4849 outcome. log_on_error ( "discord.unroutable" ) ;
4950}
@@ -64,8 +65,8 @@ struct AppState<P: JetStreamPublisher, S: ObjectStorePut, R: RequestClient> {
6465 nats : R ,
6566 public_key : VerifyingKey ,
6667 subject_prefix : NatsToken ,
67- nats_ack_timeout : Duration ,
68- nats_request_timeout : Duration ,
68+ nats_ack_timeout : NonZeroDuration ,
69+ nats_request_timeout : NonZeroDuration ,
6970}
7071
7172pub async fn provision < C : JetStreamContext > (
@@ -214,14 +215,14 @@ async fn handle_webhook_inner<P: JetStreamPublisher, S: ObjectStorePut, R: Reque
214215 subject,
215216 nats_headers,
216217 body,
217- state. nats_request_timeout ,
218+ state. nats_request_timeout . into ( ) ,
218219 )
219220 . await ;
220221 }
221222
222223 let outcome = state
223224 . publisher
224- . publish_event ( subject, nats_headers, body, state. nats_ack_timeout )
225+ . publish_event ( subject, nats_headers, body, state. nats_ack_timeout . into ( ) )
225226 . await ;
226227
227228 let status = outcome_to_status ( outcome) ;
@@ -272,6 +273,7 @@ fn empty_autocomplete_response() -> Response {
272273#[ cfg( test) ]
273274mod tests {
274275 use super :: * ;
276+
275277 use axum:: body:: Body ;
276278 use axum:: http:: Request ;
277279 use ed25519_dalek:: { Signer , SigningKey } ;
@@ -304,8 +306,8 @@ mod tests {
304306 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
305307 stream_name : NatsToken :: new ( "DISCORD" ) . unwrap ( ) ,
306308 stream_max_age : Duration :: from_secs ( 3600 ) ,
307- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
308- nats_request_timeout : Duration :: from_secs ( 2 ) ,
309+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
310+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
309311 }
310312 }
311313
@@ -518,7 +520,7 @@ mod tests {
518520 nats. hang_next_request ( ) ;
519521
520522 let mut config = test_config ( vk) ;
521- config. nats_request_timeout = Duration :: from_millis ( 10 ) ;
523+ config. nats_request_timeout = NonZeroDuration :: from_millis ( 10 ) . unwrap ( ) ;
522524
523525 let app = router ( wrap_publisher ( publisher. clone ( ) ) , nats, vk, & config) ;
524526 let body = br#"{"type":4,"id":"auto-1","data":{"name":"cmd"}}"# ;
@@ -741,8 +743,8 @@ mod tests {
741743 nats : AdvancedMockNatsClient :: new ( ) ,
742744 public_key : vk,
743745 subject_prefix : NatsToken :: new ( "custom" ) . unwrap ( ) ,
744- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
745- nats_request_timeout : Duration :: from_secs ( 2 ) ,
746+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
747+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
746748 } ;
747749
748750 let app =
@@ -811,8 +813,8 @@ mod tests {
811813 nats : AdvancedMockNatsClient :: new ( ) ,
812814 public_key : vk,
813815 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
814- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
815- nats_request_timeout : Duration :: from_secs ( 2 ) ,
816+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
817+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
816818 } ;
817819
818820 let app =
@@ -930,8 +932,8 @@ mod tests {
930932 nats : AdvancedMockNatsClient :: new ( ) ,
931933 public_key : vk,
932934 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
933- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
934- nats_request_timeout : Duration :: from_secs ( 2 ) ,
935+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
936+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
935937 } ;
936938
937939 Router :: new ( )
@@ -956,8 +958,8 @@ mod tests {
956958 nats : AdvancedMockNatsClient :: new ( ) ,
957959 public_key : vk,
958960 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
959- nats_ack_timeout : Duration :: from_millis ( 10 ) ,
960- nats_request_timeout : Duration :: from_secs ( 2 ) ,
961+ nats_ack_timeout : NonZeroDuration :: from_millis ( 10 ) . unwrap ( ) ,
962+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
961963 } ;
962964
963965 Router :: new ( )
0 commit comments