Skip to content

Commit

Permalink
Stop service uploaders crashing if no logged data
Browse files Browse the repository at this point in the history
This only happens if live or hourly logging is run before any data has
been logged. See issue #64

Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Jun 3, 2018
1 parent 984c289 commit b4f9d53
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.6.0'
_release = '1546'
_commit = '8705776'
_release = '1547'
_commit = '984c289'
4 changes: 2 additions & 2 deletions src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def __init__(self, context):
self.templater = pywws.template.Template(context, use_locale=False)
self.template_file = StringIO(self.template)
# set timestamp of first data to upload
earliest = self.context.calib_data.before(datetime.max) - max(
timedelta(days=self.catchup), self.interval)
earliest = self.context.calib_data.before(datetime.max) or datetime.max
earliest -= max(timedelta(days=self.catchup), self.interval)
self.next_update = context.status.get_datetime(
'last update', self.service_name)
if self.next_update:
Expand Down
3 changes: 2 additions & 1 deletion src/pywws/toservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ def __init__(self, context, service_name):
# set timestamp of first data to upload
self.next_update = datetime.utcnow() - max(
timedelta(days=self.catchup), self.interval)
self.next_update = min(self.next_update, self.data.before(datetime.max))
self.next_update = min(
self.next_update, self.data.before(datetime.max) or datetime.max)

def prepare_data(self, data):
"""Prepare a weather data record.
Expand Down

0 comments on commit b4f9d53

Please sign in to comment.