1- use lazy_static:: lazy_static;
1+ use std:: sync:: LazyLock ;
2+
23use reqwest:: ClientBuilder ;
34use reqwest_middleware:: { ClientBuilder as ClientWithMiddlewareBuilder , ClientWithMiddleware } ;
45use reqwest_retry:: { RetryTransientMiddleware , policies:: ExponentialBackoff } ;
@@ -7,33 +8,23 @@ const UPLOAD_RETRY_COUNT: u32 = 3;
78const OIDC_RETRY_COUNT : u32 = 10 ;
89const USER_AGENT : & str = "codspeed-runner" ;
910
10- lazy_static ! {
11- pub static ref REQUEST_CLIENT : ClientWithMiddleware = ClientWithMiddlewareBuilder :: new(
12- ClientBuilder :: new( )
13- . user_agent( USER_AGENT )
14- . build( )
15- . unwrap( )
16- )
17- . with( RetryTransientMiddleware :: new_with_policy(
18- ExponentialBackoff :: builder( ) . build_with_max_retries( UPLOAD_RETRY_COUNT )
19- ) )
20- . build( ) ;
21-
22- // Client without retry middleware for streaming uploads (can't be cloned)
23- pub static ref STREAMING_CLIENT : reqwest:: Client = ClientBuilder :: new( )
24- . user_agent( USER_AGENT )
11+ pub static REQUEST_CLIENT : LazyLock < ClientWithMiddleware > = LazyLock :: new ( || {
12+ ClientWithMiddlewareBuilder :: new ( ClientBuilder :: new ( ) . user_agent ( USER_AGENT ) . build ( ) . unwrap ( ) )
13+ . with ( RetryTransientMiddleware :: new_with_policy (
14+ ExponentialBackoff :: builder ( ) . build_with_max_retries ( UPLOAD_RETRY_COUNT ) ,
15+ ) )
2516 . build ( )
26- . unwrap ( ) ;
17+ } ) ;
2718
28- // Client with retry middleware for OIDC token requests
29- pub static ref OIDC_CLIENT : ClientWithMiddleware = ClientWithMiddlewareBuilder :: new (
30- ClientBuilder :: new( )
31- . user_agent ( USER_AGENT )
32- . build ( )
33- . unwrap ( )
34- )
35- . with( RetryTransientMiddleware :: new_with_policy(
36- ExponentialBackoff :: builder( ) . build_with_max_retries( OIDC_RETRY_COUNT )
37- ) )
38- . build( ) ;
39- }
19+ /// Client without retry middleware for streaming uploads (can't be cloned)
20+ pub static STREAMING_CLIENT : LazyLock < reqwest :: Client > =
21+ LazyLock :: new ( || ClientBuilder :: new ( ) . user_agent ( USER_AGENT ) . build ( ) . unwrap ( ) ) ;
22+
23+ /// Client with retry middleware for OIDC token requests
24+ pub static OIDC_CLIENT : LazyLock < ClientWithMiddleware > = LazyLock :: new ( || {
25+ ClientWithMiddlewareBuilder :: new ( ClientBuilder :: new ( ) . user_agent ( USER_AGENT ) . build ( ) . unwrap ( ) )
26+ . with ( RetryTransientMiddleware :: new_with_policy (
27+ ExponentialBackoff :: builder ( ) . build_with_max_retries ( OIDC_RETRY_COUNT ) ,
28+ ) )
29+ . build ( )
30+ } ) ;
0 commit comments