Skip to content

Commit

Permalink
Add some docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
matyasselmeci committed May 20, 2024
1 parent a58d201 commit fc3020f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/webapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@ def __init__(self, data=None, timestamp=0, force_update=True, cache_lifetime=60*
self.next_update = self.timestamp + self.cache_lifetime

def should_update(self):
"""Return True if we should update, either because we're past the next update time
or because force_update is True.
"""
return self.force_update or not self.data or time.time() > self.next_update

def try_again(self):
"""Set the next update time to now + the retry delay."""
self.next_update = time.time() + self.retry_delay

def update(self, data):
"""Cache new data and set the next update time to now + the cache lifetime."""
self.data = data
self.timestamp = time.time()
self.next_update = self.timestamp + self.cache_lifetime
Expand Down

0 comments on commit fc3020f

Please sign in to comment.