@@ -197,7 +197,7 @@ case class LocalTokensBucketStrategy(bucketId: String, config: LocalTokensBucket
197197 }
198198 }
199199
200- override def reset (key : String , expirationSeconds : Int )(implicit
200+ override def reset (key : String , allowedQuotas : AllowedQuota , expirationSeconds : Int )(implicit
201201 env : Env ,
202202 ec : ExecutionContext
203203 ): Future [QuotaState ] = {
@@ -218,9 +218,9 @@ case class LocalTokensBucketStrategy(bucketId: String, config: LocalTokensBucket
218218 redisCli.expire(monthlyQuotaKey(key), (toMonthEnd / 1000 ).toInt)
219219 }
220220 } yield QuotaState (
221- window = Quota (limit = config.quota .window, consumed = 0 , resetsAt = 0 ),
222- daily = Quota (limit = config.quota .daily, consumed = 0 , resetsAt = dayEnd.getMillis),
223- monthly = Quota (limit = config.quota .monthly, consumed = 0 , resetsAt = monthEnd.getMillis)
221+ window = Quota (limit = allowedQuotas .window, consumed = 0 , resetsAt = 0 ),
222+ daily = Quota (limit = allowedQuotas .daily, consumed = 0 , resetsAt = dayEnd.getMillis),
223+ monthly = Quota (limit = allowedQuotas .monthly, consumed = 0 , resetsAt = monthEnd.getMillis)
224224 )
225225 }
226226}
@@ -582,7 +582,7 @@ case class FixedWindowStrategy(bucketId: String, config: FixedWindowStrategyConf
582582 )
583583 }
584584 } else {
585- quotas(key, expirationSeconds)
585+ quotas(key, config.quota, expirationSeconds)
586586 .map(quotas =>
587587 ThrottlingResult (
588588 allowed = false ,
@@ -1037,7 +1037,10 @@ trait ThrottlingStrategy {
10371037 }
10381038 }
10391039
1040- def quotas (key : String , expirationSeconds : Int )(implicit ec : ExecutionContext , env : Env ): Future [QuotaState ] = {
1040+ def quotas (key : String , allowedQuotas : AllowedQuota , expirationSeconds : Int )(implicit
1041+ ec : ExecutionContext ,
1042+ env : Env
1043+ ): Future [QuotaState ] = {
10411044 val redisCli = client()
10421045
10431046 val dayEnd = DateTime .now().secondOfDay().withMaximumValue()
@@ -1056,17 +1059,17 @@ trait ThrottlingStrategy {
10561059 } yield {
10571060 QuotaState (
10581061 window = Quota (
1059- limit = config.quota .window,
1062+ limit = allowedQuotas .window,
10601063 consumed = throttlingCallsPerWindow,
10611064 resetsAt = now + windowTTL
10621065 ),
10631066 daily = Quota (
1064- limit = config.quota .daily,
1067+ limit = allowedQuotas .daily,
10651068 consumed = dailyCalls,
10661069 resetsAt = dayEnd.getMillis
10671070 ),
10681071 monthly = Quota (
1069- limit = config.quota .monthly,
1072+ limit = allowedQuotas .monthly,
10701073 consumed = monthlyCalls,
10711074 resetsAt = monthEnd.getMillis
10721075 )
@@ -1116,7 +1119,10 @@ trait ThrottlingStrategy {
11161119 }
11171120 }
11181121
1119- def reset (key : String , expirationSeconds : Int )(implicit env : Env , ec : ExecutionContext ): Future [QuotaState ] = {
1122+ def reset (key : String , allowedQuotas : AllowedQuota , expirationSeconds : Int )(implicit
1123+ env : Env ,
1124+ ec : ExecutionContext
1125+ ): Future [QuotaState ] = {
11201126 val redisCli = client()
11211127
11221128 val now = System .currentTimeMillis()
@@ -1144,9 +1150,9 @@ trait ThrottlingStrategy {
11441150 redisCli.expire(monthlyQuotaKey(key), (toMonthEnd / 1000 ).toInt)
11451151 }
11461152 } yield QuotaState (
1147- window = Quota (limit = config.quota .window, consumed = 0 , resetsAt = now + windowTTL),
1148- daily = Quota (limit = config.quota .daily, consumed = 0 , resetsAt = dayEnd.getMillis),
1149- monthly = Quota (limit = config.quota .monthly, consumed = 0 , resetsAt = monthEnd.getMillis)
1153+ window = Quota (limit = allowedQuotas .window, consumed = 0 , resetsAt = now + windowTTL),
1154+ daily = Quota (limit = allowedQuotas .daily, consumed = 0 , resetsAt = dayEnd.getMillis),
1155+ monthly = Quota (limit = allowedQuotas .monthly, consumed = 0 , resetsAt = monthEnd.getMillis)
11501156 )
11511157 }
11521158
0 commit comments