Skip to content

Commit

Permalink
Fix OverflowError on celery worker (#3899)
Browse files Browse the repository at this point in the history
  • Loading branch information
guyco33 authored and Omer Lachish committed Jun 16, 2019
1 parent ac293c7 commit 21a27ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ def should_schedule_next(previous_iteration, now, interval, time=None, day_of_we
next_iteration = (previous_iteration + datetime.timedelta(days=days_delay) +
datetime.timedelta(days=days_to_add)).replace(hour=hour, minute=minute)
if failures:
next_iteration += datetime.timedelta(minutes=2**failures)
try:
next_iteration += datetime.timedelta(minutes=2**failures)
except OverflowError:
return False
return now > next_iteration


Expand Down
5 changes: 5 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ def test_backoff(self):
self.assertFalse(models.should_schedule_next(two_hours_ago, now,
"3600", failures=10))

def test_next_iteration_overflow(self):
now = utcnow()
two_hours_ago = now - datetime.timedelta(hours=2)
self.assertFalse(models.should_schedule_next(two_hours_ago, now, "3600", failures=32))


class QueryOutdatedQueriesTest(BaseTestCase):
# TODO: this test can be refactored to use mock version of should_schedule_next to simplify it.
Expand Down

0 comments on commit 21a27ee

Please sign in to comment.