Skip to content

Commit a36fe38

Browse files
BeneCollyridamgsong
authored andcommitted
Fix negative delays in sqlite middleware
1 parent d06e0c2 commit a36fe38

File tree

1 file changed

+7
-3
lines changed
  • epo_ops/middlewares/throttle/storages

1 file changed

+7
-3
lines changed

epo_ops/middlewares/throttle/storages/sqlite.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ def delay_for(self, service):
120120
)
121121
else:
122122
next_run = _now + timedelta(seconds=60.0 / r[limit])
123-
td = next_run - _now
124-
ts = td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6
125-
return ts / 10 ** 6
123+
124+
if next_run < _now:
125+
return 0.0
126+
else:
127+
td = next_run - _now
128+
ts = td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6
129+
return ts / 10 ** 6
126130

127131
def update(self, headers):
128132
"This method is a public interface for a throttle storage class"

0 commit comments

Comments
 (0)