only download while online

This commit is contained in:
j 2016-01-14 09:57:26 +05:30
parent 82f7e83e74
commit 3748930d7c

View file

@ -41,21 +41,31 @@ class Downloads(Thread):
if state.nodes.is_online(u.id): if state.nodes.is_online(u.id):
logger.debug('DOWNLOAD %s %s', t.item, u) logger.debug('DOWNLOAD %s %s', t.item, u)
r = state.nodes.download(u.id, t.item) r = state.nodes.download(u.id, t.item)
logger.debug('download ok? %s', r)
return True return True
return False return False
def run(self): def run(self):
time.sleep(2) self.wait(10)
while self._running: while self._running:
self.wait_online()
with db.session(): with db.session():
self.download_next() self.download_next()
time.sleep(0.5) self.wait(10)
def join(self): def join(self):
self._running = False self._running = False
return Thread.join(self) 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): class ScrapeThread(Thread):
def __init__(self): def __init__(self):