omnata-plugin-runtime 0.2.80__py3-none-any.whl → 0.2.81__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omnata_plugin_runtime/rate_limiting.py +34 -3
- {omnata_plugin_runtime-0.2.80.dist-info → omnata_plugin_runtime-0.2.81.dist-info}/METADATA +1 -1
- {omnata_plugin_runtime-0.2.80.dist-info → omnata_plugin_runtime-0.2.81.dist-info}/RECORD +5 -5
- {omnata_plugin_runtime-0.2.80.dist-info → omnata_plugin_runtime-0.2.81.dist-info}/LICENSE +0 -0
- {omnata_plugin_runtime-0.2.80.dist-info → omnata_plugin_runtime-0.2.81.dist-info}/WHEEL +0 -0
@@ -132,11 +132,19 @@ class ApiLimits(SubscriptableBaseModel):
|
|
132
132
|
):
|
133
133
|
longest_wait = rate_limit_state.wait_until
|
134
134
|
for request_rate in self.request_rates:
|
135
|
+
print(request_rate)
|
135
136
|
if rate_limit_state.previous_request_timestamps is not None and len(rate_limit_state.previous_request_timestamps) > 0:
|
137
|
+
previous_request_timestamps = rate_limit_state.get_relevant_history(request_rate)
|
138
|
+
print(f"previous_request_timestamps: {len(previous_request_timestamps)}")
|
136
139
|
request_index = request_rate.request_count - 1
|
137
|
-
if request_index > len(
|
138
|
-
|
139
|
-
|
140
|
+
if request_index > len(previous_request_timestamps) - 1:
|
141
|
+
continue # we have not yet made enough requests to hit this rate limit
|
142
|
+
request_index = len(previous_request_timestamps) - 1
|
143
|
+
timestamp_at_horizon = previous_request_timestamps[request_index]
|
144
|
+
print("timestamp_at_horizon: " + str(timestamp_at_horizon))
|
145
|
+
now = datetime.datetime.now().astimezone(datetime.timezone.utc)
|
146
|
+
seconds_since_horizon = (timestamp_at_horizon - now).total_seconds()
|
147
|
+
print("seconds_since_horizon: " + str(seconds_since_horizon))
|
140
148
|
next_allowed_request = timestamp_at_horizon + datetime.timedelta(
|
141
149
|
seconds=request_rate.number_of_seconds()
|
142
150
|
)
|
@@ -257,6 +265,29 @@ class RateLimitState(SubscriptableBaseModel):
|
|
257
265
|
ts for ts in self.previous_request_timestamps if ts > irrelevance_horizon
|
258
266
|
]
|
259
267
|
|
268
|
+
def get_relevant_history(self, request_rate: RequestRateLimit = None):
|
269
|
+
"""
|
270
|
+
Returns the previous requests which are relevant to a specific rate limiting window.
|
271
|
+
First, we prune out timestamps which are older than the time window.
|
272
|
+
We also only need to keep timestamps up until the request count for the rate limit.
|
273
|
+
For example:
|
274
|
+
- Rate limit is 10 requests per 10 seconds
|
275
|
+
- If (somehow, for the sake of argument) there were 20 requests in the last 10 seconds,
|
276
|
+
we only need to keep the most recent 10 to base our calculation on
|
277
|
+
"""
|
278
|
+
if request_rate is None:
|
279
|
+
return self.previous_request_timestamps
|
280
|
+
longest_window_seconds = request_rate.number_of_seconds()
|
281
|
+
irrelevance_horizon = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(
|
282
|
+
seconds=longest_window_seconds
|
283
|
+
)
|
284
|
+
|
285
|
+
pruned = [ts for ts in self.previous_request_timestamps if ts > irrelevance_horizon]
|
286
|
+
if len(pruned) > request_rate.request_count:
|
287
|
+
return pruned[:request_rate.request_count]
|
288
|
+
else:
|
289
|
+
return pruned
|
290
|
+
|
260
291
|
|
261
292
|
class RequestRateLimit(SubscriptableBaseModel):
|
262
293
|
"""
|
@@ -5,8 +5,8 @@ omnata_plugin_runtime/forms.py,sha256=_KqSMQG749wImLKxPZh3B3doTZMbP5jDvF6BhQNkPC
|
|
5
5
|
omnata_plugin_runtime/logging.py,sha256=Q6eSqrr3SzwfVAg4r4sV1dlxeNS_PzOtZfieoWUEOZQ,3232
|
6
6
|
omnata_plugin_runtime/omnata_plugin.py,sha256=eshPKK9I4o1kVKXIJoihwNuje-uOnDXA7x5UlzVv_i8,86096
|
7
7
|
omnata_plugin_runtime/plugin_entrypoints.py,sha256=dV_JOEWffdkAkofFYJMAsM_-gE9OpM2-paI2dsh5Rzo,24352
|
8
|
-
omnata_plugin_runtime/rate_limiting.py,sha256=
|
9
|
-
omnata_plugin_runtime-0.2.
|
10
|
-
omnata_plugin_runtime-0.2.
|
11
|
-
omnata_plugin_runtime-0.2.
|
12
|
-
omnata_plugin_runtime-0.2.
|
8
|
+
omnata_plugin_runtime/rate_limiting.py,sha256=Ur_TjtpemAEMQxxoKq4NeR1w0t1OQkyq6ANgbmOGlXQ,16642
|
9
|
+
omnata_plugin_runtime-0.2.81.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
|
10
|
+
omnata_plugin_runtime-0.2.81.dist-info/METADATA,sha256=fskFBfEwVeyauJHnZ2Q8y25R038BrfsLxzBi7mKnmPE,1086
|
11
|
+
omnata_plugin_runtime-0.2.81.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
12
|
+
omnata_plugin_runtime-0.2.81.dist-info/RECORD,,
|
File without changes
|
File without changes
|