Skip to content

Commit

Permalink
Improved upload thread starting
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 Aug 24, 2018
1 parent 582db92 commit 98c4fe5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 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 = '1589'
_commit = '1f0a458'
_release = '1590'
_commit = '582db92'
27 changes: 14 additions & 13 deletions src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,26 @@
import pywws.template


class Queue(deque):
def __init__(self, start, *arg, **kw):
super(Queue, self).__init__(*arg, **kw)
self._start = start

def append(self, x):
super(Queue, self).append(x)
if x is None:
return
self.append = super(Queue, self).append
self._start()


class ServiceBase(threading.Thread):
interval = timedelta(seconds=40)

def __init__(self, context):
super(ServiceBase, self).__init__()
self.context = context
self.queue = deque()
self.queue = Queue(self.start)

def run(self):
self.logger.debug('thread started ' + self.name)
Expand Down Expand Up @@ -159,9 +172,6 @@ def do_catchup(self):
if len(self.queue) >= 60:
break
self.queue_data(data['idx'], data, False)
# start upload thread
if self.queue and not self.is_alive():
self.start()

def upload(self, live_data=None, test_mode=False, option=''):
if test_mode:
Expand All @@ -177,9 +187,6 @@ def upload(self, live_data=None, test_mode=False, option=''):
idx = self.context.calib_data.after(data['idx'] + SECOND)
if live_data and not idx:
self.queue_data(live_data['idx'], live_data, True)
# start upload thread
if self.queue and not self.is_alive():
self.start()


class LiveDataService(DataServiceBase):
Expand All @@ -198,9 +205,6 @@ def upload(self, live_data=None, test_mode=False, option=''):
if test_mode:
timestamp = None
self.queue_data(timestamp, data, bool(live_data))
# start upload thread
if self.queue and not self.is_alive():
self.start()

def upload_batch(self):
# remove stale uploads from queue
Expand All @@ -224,9 +228,6 @@ def do_catchup(self):

def upload(self, live_data=None, option=''):
self.queue.append(option)
# start upload thread
if self.queue and not self.is_alive():
self.start()

def upload_batch(self):
# make list of files to upload
Expand Down

0 comments on commit 98c4fe5

Please sign in to comment.