@@ -10,6 +10,7 @@ use models::{
10
10
Client ,
11
11
} ;
12
12
use options:: Opts ;
13
+ use progenitor:: progenitor_client:: ResponseValue ;
13
14
use rand:: seq:: SliceRandom ;
14
15
use reqwest:: header:: { HeaderMap , HeaderValue } ;
15
16
use std:: {
@@ -70,65 +71,69 @@ async fn main() -> eyre::Result<()> {
70
71
71
72
pb. set_style ( spinner_style) ;
72
73
73
- let mut set = JoinSet :: new ( ) ;
74
-
75
74
for region in & APP_CONFIG . regions {
76
- for _ in 0 ..APP_CONFIG . attempts {
77
- let pb = pb. clone ( ) ;
78
- set. spawn ( async move {
79
- let ( country_code, continent_code) = match region {
80
- options:: EarthRegion :: Country ( c) => {
81
- ( Some ( c. to_country ( ) . alpha2 ( ) . to_string ( ) ) , None )
82
- }
83
- options:: EarthRegion :: Continent ( con) => (
84
- None ,
85
- Some (
86
- match con {
87
- keshvar:: Continent :: Africa => "AF" ,
88
- keshvar:: Continent :: Antarctica => "AN" ,
89
- keshvar:: Continent :: Asia => "AS" ,
90
- keshvar:: Continent :: Australia => "OC" ,
91
- keshvar:: Continent :: Europe => "EU" ,
92
- keshvar:: Continent :: NorthAmerica => "NA" ,
93
- keshvar:: Continent :: SouthAmerica => "SA" ,
94
- }
95
- . to_string ( ) ,
75
+ for chunk in ( 0 ..APP_CONFIG . attempts ) . collect :: < Vec < _ > > ( ) . chunks ( 100 ) {
76
+ let mut chunk_set = JoinSet :: new ( ) ;
77
+
78
+ for _ in chunk {
79
+ let pb = pb. clone ( ) ;
80
+ let region = region. clone ( ) ;
81
+ let endpoint = endpoint. clone ( ) ;
82
+
83
+ chunk_set. spawn ( async move {
84
+ let ( country_code, continent_code) = match region {
85
+ options:: EarthRegion :: Country ( c) => {
86
+ ( Some ( c. to_country ( ) . alpha2 ( ) . to_string ( ) ) , None )
87
+ }
88
+ options:: EarthRegion :: Continent ( con) => (
89
+ None ,
90
+ Some (
91
+ match con {
92
+ keshvar:: Continent :: Africa => "AF" ,
93
+ keshvar:: Continent :: Antarctica => "AN" ,
94
+ keshvar:: Continent :: Asia => "AS" ,
95
+ keshvar:: Continent :: Australia => "OC" ,
96
+ keshvar:: Continent :: Europe => "EU" ,
97
+ keshvar:: Continent :: NorthAmerica => "NA" ,
98
+ keshvar:: Continent :: SouthAmerica => "SA" ,
99
+ }
100
+ . to_string ( ) ,
101
+ ) ,
96
102
) ,
97
- ) ,
98
- _ => ( None , None ) ,
99
- } ;
100
-
101
- debug ! ( ?country_code, "Sending job to country" ) ;
102
-
103
- let result = API_CLIENT
104
- . perform_icmp ( & PerformIcmpBody {
105
- configuration : Some ( PerformIcmpBodyConfiguration {
106
- payload_size : Some ( 56.0 ) ,
107
- timeout_millis : None ,
108
- attempts : Some ( APP_CONFIG . count as f64 ) ,
109
- } ) ,
110
- country_code,
111
- continent_code,
112
- hostnames : vec ! [ endpoint. to_string( ) ] ,
113
- isp_regex : None ,
114
- } )
115
- . await
116
- . context ( "Failed to send job" ) ;
117
-
118
- pb. inc ( 1 ) ;
119
-
120
- result
121
- } ) ;
103
+ _ => ( None , None ) ,
104
+ } ;
105
+
106
+ debug ! ( ?country_code, "Sending job to country" ) ;
107
+
108
+ let result = API_CLIENT
109
+ . perform_icmp ( & PerformIcmpBody {
110
+ configuration : Some ( PerformIcmpBodyConfiguration {
111
+ payload_size : Some ( 56.0 ) ,
112
+ timeout_millis : None ,
113
+ attempts : Some ( APP_CONFIG . count as f64 ) ,
114
+ } ) ,
115
+ country_code,
116
+ continent_code,
117
+ hostnames : vec ! [ endpoint. to_string( ) ] ,
118
+ isp_regex : None ,
119
+ } )
120
+ . await
121
+ . context ( "Failed to send job" ) ;
122
+
123
+ pb. inc ( 1 ) ;
124
+
125
+ result
126
+ } ) ;
127
+ }
128
+
129
+ while let Some ( res) = chunk_set. join_next ( ) . await {
130
+ let out = res??;
131
+ tracing:: debug!( "Response {:?}" , out) ;
132
+ display_job ( & pb, & APP_CONFIG , & out) . await ;
133
+ }
122
134
}
123
135
}
124
136
125
- while let Some ( res) = set. join_next ( ) . await {
126
- let out = res??;
127
- tracing:: debug!( "Response {:?}" , out) ;
128
-
129
- display_job ( & pb, & APP_CONFIG , & out) . await ;
130
- }
131
-
132
137
pb. finish ( ) ;
133
138
Ok ( ( ) )
134
139
}
0 commit comments