only download while online
This commit is contained in:
parent
82f7e83e74
commit
3748930d7c
1 changed files with 13 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue