From 21a27ee0b132f2134e69b21df71480a9ff9e948d Mon Sep 17 00:00:00 2001 From: Guy Cohen Date: Sun, 16 Jun 2019 11:34:29 +0300 Subject: [PATCH] Fix OverflowError on celery worker (#3899) --- redash/models/__init__.py | 5 ++++- tests/test_models.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/redash/models/__init__.py b/redash/models/__init__.py index 5abe93e9b6..574ab0efdb 100644 --- a/redash/models/__init__.py +++ b/redash/models/__init__.py @@ -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 diff --git a/tests/test_models.py b/tests/test_models.py index 465d6bf65e..3e222e0d66 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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.