1- use std:: { collections:: HashMap , sync:: Arc } ;
1+ use std:: { collections:: HashMap , sync:: Arc , time :: Duration } ;
22
33use reqwest:: { header:: HeaderMap , Client , Method } ;
4+ use tokio:: time;
45
56use crate :: metrics:: metrics:: Metrics ;
67
@@ -10,9 +11,10 @@ pub struct Scheduler<'a> {
1011 url : String ,
1112 body : Option < String > ,
1213 form_params : HashMap < String , String > ,
14+ headers : HeaderMap ,
1315 concurrency : u64 ,
1416 duration : u64 ,
15- headers : HeaderMap ,
17+ timeout : u64 ,
1618}
1719
1820impl < ' a > Scheduler < ' a > {
@@ -25,16 +27,18 @@ impl<'a> Scheduler<'a> {
2527 headers : HeaderMap ,
2628 concurrency : u64 ,
2729 duration : u64 ,
30+ timeout : u64 ,
2831 ) -> Self {
2932 Scheduler {
3033 metrics,
3134 method,
3235 url,
3336 body,
3437 form_params,
38+ headers,
3539 concurrency,
3640 duration,
37- headers ,
41+ timeout ,
3842 }
3943 }
4044
@@ -52,6 +56,7 @@ impl<'a> Scheduler<'a> {
5256 let form_params = self . form_params . clone ( ) ;
5357 let headers = headers. clone ( ) ;
5458 let duration = self . duration ;
59+ let timeout = self . timeout ;
5560 let metrics = Arc :: clone ( self . metrics ) ;
5661
5762 tasks. push ( tokio:: spawn ( async move {
@@ -62,8 +67,9 @@ impl<'a> Scheduler<'a> {
6267 url,
6368 body,
6469 form_params,
65- duration,
6670 headers,
71+ duration,
72+ timeout,
6773 )
6874 . await ;
6975 } ) ) ;
@@ -107,10 +113,15 @@ impl<'a> Scheduler<'a> {
107113 url : String ,
108114 body : Option < String > ,
109115 form_params : HashMap < String , String > ,
110- duration : u64 ,
111116 headers : HeaderMap ,
117+ duration : u64 ,
118+ timeout : u64 ,
112119 ) {
113- let client = Client :: builder ( ) . default_headers ( headers) . build ( ) . unwrap ( ) ;
120+ let client = Client :: builder ( )
121+ . default_headers ( headers)
122+ . timeout ( Duration :: from_secs ( timeout) )
123+ . build ( )
124+ . unwrap ( ) ;
114125
115126 loop {
116127 let result =
0 commit comments