Skip to content

Commit

Permalink
Make service 'catchup' cli option send all data
Browse files Browse the repository at this point in the history
Previously it would only send a batch of 60 before exiting.

Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 24, 2018
1 parent 98c4fe5 commit 15bd4d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 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.8.0'
_release = '1590'
_commit = '582db92'
_release = '1591'
_commit = '98c4fe5'
20 changes: 14 additions & 6 deletions src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def append(self, x):
self.append = super(Queue, self).append
self._start()

def full(self):
return len(self) >= 50


class ServiceBase(threading.Thread):
interval = timedelta(seconds=40)
Expand Down Expand Up @@ -166,11 +169,16 @@ def upload_batch(self):


class CatchupDataService(DataServiceBase):
def do_catchup(self):
def do_catchup(self, do_all=False):
start = self.last_update + self.interval
for data in self.context.calib_data[start:]:
if len(self.queue) >= 60:
break
if do_all:
while self.queue.full():
self.context.shutdown.wait(4.0)
if self.context.shutdown.is_set():
return
elif self.queue.full() or self.context.shutdown.is_set():
return
self.queue_data(data['idx'], data, False)

def upload(self, live_data=None, test_mode=False, option=''):
Expand All @@ -190,7 +198,7 @@ def upload(self, live_data=None, test_mode=False, option=''):


class LiveDataService(DataServiceBase):
def do_catchup(self):
def do_catchup(self, do_all=False):
pass

def upload(self, live_data=None, test_mode=False, option=''):
Expand Down Expand Up @@ -220,7 +228,7 @@ def upload_batch(self):


class FileService(ServiceBase):
def do_catchup(self):
def do_catchup(self, do_all=False):
pending = eval(self.context.status.get(
'pending', self.service_name, '[]'))
if pending:
Expand Down Expand Up @@ -299,7 +307,7 @@ def main(class_, argv=None):
for file in args.file:
uploader.upload(option=os.path.abspath(file))
elif issubclass(class_, CatchupDataService) and args.catchup:
uploader.do_catchup()
uploader.do_catchup(do_all=True)
else:
uploader.upload(test_mode=True)
uploader.stop()
Expand Down

0 comments on commit 15bd4d0

Please sign in to comment.