Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Remove duplication in the staleness check
Browse files Browse the repository at this point in the history
  • Loading branch information
jabley committed Aug 14, 2014
1 parent d4530ef commit 60e16c8
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions backdrop/core/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ def name(self):
return self.config['name']

def is_recent_enough(self):
max_age_expected = self.get_max_age_expected()
seconds_out_of_date = self.get_seconds_out_of_date()

return seconds_out_of_date is None or seconds_out_of_date < 0

def get_max_age_expected(self):
return self.config.get('max_age_expected',
DEFAULT_MAX_AGE_EXPECTED)

def get_last_updated(self):
return self.storage.get_last_updated(self.name)

def get_seconds_out_of_date(self):
now = timeutils.now()
max_age_expected = self.get_max_age_expected()
last_updated = self.get_last_updated()

"""
Expand All @@ -40,30 +51,9 @@ def is_recent_enough(self):
because we already know that, right?
"""
if max_age_expected is None or not last_updated:
return True

max_age_expected_delta = datetime.timedelta(seconds=max_age_expected)

return (now - last_updated) < max_age_expected_delta

def get_max_age_expected(self):
return self.config.get('max_age_expected',
DEFAULT_MAX_AGE_EXPECTED)

def get_last_updated(self):
return self.storage.get_last_updated(self.name)

def get_seconds_out_of_date(self):
now = timeutils.now()

if not self.get_last_updated() or self.get_max_age_expected() is None:
return None
else:
last_updated = self.get_last_updated()

max_age_delta = datetime.timedelta(
seconds=self.get_max_age_expected()
)
max_age_delta = datetime.timedelta(seconds=max_age_expected)

return int((
now - last_updated - max_age_delta
Expand Down

0 comments on commit 60e16c8

Please sign in to comment.