11use std:: time:: Duration ;
22
3- use bencher_json:: { system:: config:: JsonRateLimit , DateTime , PlanLevel } ;
3+ use bencher_json:: { system:: config:: JsonRateLimiting , DateTime , PlanLevel } ;
44use bencher_license:: Licensor ;
55use slog:: Logger ;
66
@@ -19,14 +19,14 @@ const DAY: Duration = Duration::from_secs(24 * 60 * 60);
1919const UNCLAIMED_RATE_LIMIT : u32 = u8:: MAX as u32 ;
2020const CLAIMED_RATE_LIMIT : u32 = u16:: MAX as u32 ;
2121
22- pub struct RateLimit {
22+ pub struct RateLimiting {
2323 pub window : Duration ,
24- pub unclaimed : u32 ,
25- pub claimed : u32 ,
24+ pub unclaimed_limit : u32 ,
25+ pub claimed_limit : u32 ,
2626}
2727
2828#[ derive( Debug , thiserror:: Error ) ]
29- pub enum RateLimitError {
29+ pub enum RateLimitingError {
3030 #[ error( "User ({uuid}) has exceeded the daily rate limit ({rate_limit}) for {resource} creation. Please, reduce your daily usage." , uuid = user. uuid) ]
3131 User {
3232 user : QueryUser ,
@@ -65,40 +65,40 @@ pub enum RateLimitError {
6565 } ,
6666}
6767
68- impl From < JsonRateLimit > for RateLimit {
69- fn from ( json : JsonRateLimit ) -> Self {
70- let JsonRateLimit {
68+ impl From < JsonRateLimiting > for RateLimiting {
69+ fn from ( json : JsonRateLimiting ) -> Self {
70+ let JsonRateLimiting {
7171 window,
72- unclaimed ,
73- claimed ,
72+ unclaimed_limit ,
73+ claimed_limit ,
7474 } = json;
7575 Self {
7676 window : window. map ( u64:: from) . map_or ( DAY , Duration :: from_secs) ,
77- unclaimed : unclaimed . unwrap_or ( UNCLAIMED_RATE_LIMIT ) ,
78- claimed : claimed . unwrap_or ( CLAIMED_RATE_LIMIT ) ,
77+ unclaimed_limit : unclaimed_limit . unwrap_or ( UNCLAIMED_RATE_LIMIT ) ,
78+ claimed_limit : claimed_limit . unwrap_or ( CLAIMED_RATE_LIMIT ) ,
7979 }
8080 }
8181}
8282
83- impl Default for RateLimit {
83+ impl Default for RateLimiting {
8484 fn default ( ) -> Self {
8585 Self {
8686 window : DAY ,
87- unclaimed : UNCLAIMED_RATE_LIMIT ,
88- claimed : CLAIMED_RATE_LIMIT ,
87+ unclaimed_limit : UNCLAIMED_RATE_LIMIT ,
88+ claimed_limit : CLAIMED_RATE_LIMIT ,
8989 }
9090 }
9191}
9292
93- impl RateLimit {
93+ impl RateLimiting {
9494 pub async fn new (
9595 log : & Logger ,
9696 conn : & tokio:: sync:: Mutex < DbConnection > ,
9797 licensor : & Licensor ,
9898 is_bencher_cloud : bool ,
99- rate_limit : Option < JsonRateLimit > ,
100- ) -> Result < Self , RateLimitError > {
101- let Some ( rate_limit ) = rate_limit else {
99+ rate_limiting : Option < JsonRateLimiting > ,
100+ ) -> Result < Self , RateLimitingError > {
101+ let Some ( rate_limiting ) = rate_limiting else {
102102 return Ok ( Self :: default ( ) ) ;
103103 } ;
104104
@@ -118,7 +118,7 @@ impl RateLimit {
118118 }
119119 }
120120
121- Ok ( rate_limit . into ( ) )
121+ Ok ( rate_limiting . into ( ) )
122122 }
123123
124124 pub fn window ( & self ) -> ( DateTime , DateTime ) {
0 commit comments