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):