Skip to content

Commit

Permalink
Reduce intra-thread setting of "last update"
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Jun 4, 2018
1 parent ca9d3ec commit 06f4f72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 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 = '1548'
_commit = 'b4f9d53'
_release = '1549'
_commit = 'ca9d3ec'
13 changes: 8 additions & 5 deletions src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def __init__(self, context):
if self.template:
self.templater = pywws.template.Template(context, use_locale=False)
self.template_file = StringIO(self.template)
# get time stamp of last uploaded data
self.last_update = self.context.status.get_datetime(
'last update', self.service_name)
# create upload thread
self.upload_thread = UploadThread(self, context)
self.stop = self.upload_thread.stop
Expand Down Expand Up @@ -164,12 +167,10 @@ def prepare_data(self, data):
return eval('{' + data_str + '}')

def next_data(self, catchup, live_data):
last_update = self.context.status.get_datetime(
'last update', self.service_name)
if not catchup:
start = self.context.calib_data.before(datetime.max)
elif last_update:
start = last_update + self.interval
elif self.last_update:
start = self.last_update + self.interval
else:
start = datetime.utcnow() - max(
timedelta(days=self.catchup), self.interval)
Expand All @@ -181,10 +182,12 @@ def next_data(self, catchup, live_data):
for data in self.context.calib_data[start:stop]:
if data['idx'] >= next_update and self.valid_data(data):
yield data, False
next_update = data['idx'] + self.interval
self.last_update = data['idx']
next_update = self.last_update + self.interval
if (live_data and live_data['idx'] >= next_update and
self.valid_data(live_data)):
yield live_data, True
self.last_update = live_data['idx']

def valid_data(self, data):
return True
Expand Down

0 comments on commit 06f4f72

Please sign in to comment.