From 3748930d7cee842ccf7f56708ccc493968937c33 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 14 Jan 2016 09:57:26 +0530 Subject: [PATCH] only download while online --- oml/downloads.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/oml/downloads.py b/oml/downloads.py index 5a80de3..cee6396 100644 --- a/oml/downloads.py +++ b/oml/downloads.py @@ -41,21 +41,31 @@ class Downloads(Thread): if state.nodes.is_online(u.id): logger.debug('DOWNLOAD %s %s', t.item, u) r = state.nodes.download(u.id, t.item) - logger.debug('download ok? %s', r) return True return False def run(self): - time.sleep(2) + self.wait(10) while self._running: + self.wait_online() with db.session(): self.download_next() - time.sleep(0.5) + self.wait(10) def join(self): self._running = False return Thread.join(self) + def wait_online(self): + while not state.online: + self.wait(5) + + def wait(self, timeout): + step = min(timeout, 1) + while self._running and timeout > 0: + time.sleep(step) + timeout -= step + class ScrapeThread(Thread): def __init__(self):