MCPcopy Create free account
hub / github.com/aws/aws-cli / consume

Method consume

awscli/s3transfer/bandwidth.py:248–277  ·  view source on GitHub ↗

Consume an a requested amount :type amt: int :param amt: The amount of bytes to request to consume :type request_token: RequestToken :param request_token: The token associated to the consumption request that is used to identify the request. So if a

(self, amt, request_token)

Source from the content-addressed store, hash-verified

246 self._consumption_scheduler = ConsumptionScheduler()
247
248 def consume(self, amt, request_token):
249 """Consume an a requested amount
250
251 :type amt: int
252 :param amt: The amount of bytes to request to consume
253
254 :type request_token: RequestToken
255 :param request_token: The token associated to the consumption
256 request that is used to identify the request. So if a
257 RequestExceededException is raised the token should be used
258 in subsequent retry consume() request.
259
260 :raises RequestExceededException: If the consumption amount would
261 exceed the maximum allocated bandwidth
262
263 :rtype: int
264 :returns: The amount consumed
265 """
266 with self._lock:
267 time_now = self._time_utils.time()
268 if self._consumption_scheduler.is_scheduled(request_token):
269 return self._release_requested_amt_for_scheduled_request(
270 amt, request_token, time_now
271 )
272 elif self._projected_to_exceed_max_rate(amt, time_now):
273 self._raise_request_exceeded_exception(
274 amt, request_token, time_now
275 )
276 else:
277 return self._release_requested_amt(amt, time_now)
278
279 def _projected_to_exceed_max_rate(self, amt, time_now):
280 projected_rate = self._rate_tracker.get_projected_rate(amt, time_now)