Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the logic around schedule['until'] easier to read #3376

Merged
merged 3 commits into from
Feb 3, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
import csv
import datetime
import calendar
import functools
import hashlib
import itertools
import logging
import time
import pytz
from functools import reduce

import xlsxwriter
from six import python_2_unicode_compatible, text_type
Expand Down Expand Up @@ -554,19 +550,21 @@ def outdated_queries(cls):
.options(joinedload(Query.latest_query_data).load_only('retrieved_at'))
.filter(Query.schedule.isnot(None))
.order_by(Query.id))

now = utils.utcnow()
outdated_queries = {}
scheduled_queries_executions.refresh()

for query in queries:
schedule_until = pytz.utc.localize(datetime.datetime.strptime(
query.schedule['until'], '%Y-%m-%d')) if query.schedule['until'] else None
if (query.schedule['interval'] == None or (
schedule_until != None and (
schedule_until <= now))):
if query.schedule['interval'] is None:
continue

if query.schedule['until'] is not None:
schedule_until = pytz.utc.localize(datetime.datetime.strptime(query.schedule['until'], '%Y-%m-%d'))

if schedule_until <= now:
continue

if query.latest_query_data:
retrieved_at = query.latest_query_data.retrieved_at
else:
Expand Down