@@ -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 ( ) {
@@ -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 > (
@@ -153,7 +154,7 @@ async fn handle_webhook_inner<P: JetStreamPublisher, S: ObjectStorePut, R: Reque
153154 & state. subject_prefix ,
154155 "invalid_json" ,
155156 body,
156- state. nats_ack_timeout ,
157+ state. nats_ack_timeout . into ( ) ,
157158 )
158159 . await ;
159160 return StatusCode :: BAD_REQUEST . into_response ( ) ;
@@ -166,7 +167,7 @@ async fn handle_webhook_inner<P: JetStreamPublisher, S: ObjectStorePut, R: Reque
166167 & state. subject_prefix ,
167168 "missing_type" ,
168169 body,
169- state. nats_ack_timeout ,
170+ state. nats_ack_timeout . into ( ) ,
170171 )
171172 . await ;
172173 return StatusCode :: BAD_REQUEST . into_response ( ) ;
@@ -184,7 +185,7 @@ async fn handle_webhook_inner<P: JetStreamPublisher, S: ObjectStorePut, R: Reque
184185 & state. subject_prefix ,
185186 "unknown_interaction_type" ,
186187 body,
187- state. nats_ack_timeout ,
188+ state. nats_ack_timeout . into ( ) ,
188189 )
189190 . await ;
190191 return StatusCode :: BAD_REQUEST . into_response ( ) ;
@@ -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) ;
@@ -304,8 +305,8 @@ mod tests {
304305 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
305306 stream_name : NatsToken :: new ( "DISCORD" ) . unwrap ( ) ,
306307 stream_max_age : Duration :: from_secs ( 3600 ) ,
307- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
308- nats_request_timeout : Duration :: from_secs ( 2 ) ,
308+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
309+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
309310 }
310311 }
311312
@@ -518,7 +519,7 @@ mod tests {
518519 nats. hang_next_request ( ) ;
519520
520521 let mut config = test_config ( vk) ;
521- config. nats_request_timeout = Duration :: from_millis ( 10 ) ;
522+ config. nats_request_timeout = NonZeroDuration :: from_millis ( 10 ) . unwrap ( ) ;
522523
523524 let app = router ( wrap_publisher ( publisher. clone ( ) ) , nats, vk, & config) ;
524525 let body = br#"{"type":4,"id":"auto-1","data":{"name":"cmd"}}"# ;
@@ -741,8 +742,8 @@ mod tests {
741742 nats : AdvancedMockNatsClient :: new ( ) ,
742743 public_key : vk,
743744 subject_prefix : NatsToken :: new ( "custom" ) . unwrap ( ) ,
744- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
745- nats_request_timeout : Duration :: from_secs ( 2 ) ,
745+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
746+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
746747 } ;
747748
748749 let app =
@@ -811,8 +812,8 @@ mod tests {
811812 nats : AdvancedMockNatsClient :: new ( ) ,
812813 public_key : vk,
813814 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
814- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
815- nats_request_timeout : Duration :: from_secs ( 2 ) ,
815+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
816+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
816817 } ;
817818
818819 let app =
@@ -930,8 +931,8 @@ mod tests {
930931 nats : AdvancedMockNatsClient :: new ( ) ,
931932 public_key : vk,
932933 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
933- nats_ack_timeout : Duration :: from_secs ( 10 ) ,
934- nats_request_timeout : Duration :: from_secs ( 2 ) ,
934+ nats_ack_timeout : NonZeroDuration :: from_secs ( 10 ) . unwrap ( ) ,
935+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
935936 } ;
936937
937938 Router :: new ( )
@@ -956,8 +957,8 @@ mod tests {
956957 nats : AdvancedMockNatsClient :: new ( ) ,
957958 public_key : vk,
958959 subject_prefix : NatsToken :: new ( "discord" ) . unwrap ( ) ,
959- nats_ack_timeout : Duration :: from_millis ( 10 ) ,
960- nats_request_timeout : Duration :: from_secs ( 2 ) ,
960+ nats_ack_timeout : NonZeroDuration :: from_millis ( 10 ) . unwrap ( ) ,
961+ nats_request_timeout : NonZeroDuration :: from_secs ( 2 ) . unwrap ( ) ,
961962 } ;
962963
963964 Router :: new ( )
0 commit comments