get preview in tasks

This commit is contained in:
j 2016-01-24 13:14:43 +05:30
parent 168b293514
commit 5c5c8ac39b
4 changed files with 26 additions and 16 deletions

View file

@ -183,7 +183,9 @@ class Changelog(db.Model):
i = Item.get(itemid) i = Item.get(itemid)
if i: if i:
i.sync_metadata() i.sync_metadata()
i.get_preview() if state.tasks:
#state.tasks.queue('syncmetadata', [i.id])
state.tasks.queue('getpreview', i.id)
return True return True
def action_removeitem(self, user, timestamp, itemid): def action_removeitem(self, user, timestamp, itemid):

View file

@ -791,8 +791,15 @@ def update_sort_table():
s.commit() s.commit()
def get_preview(id):
#logger.debug('get_preview(%s)', id)
with db.session():
i = Item.get(id)
if i:
i.get_preview()
def sync_metadata(ids=None): def sync_metadata(ids=None):
#logger.debug('sync_metadata(%s)', len(ids) if ids else ids) #logger.debug('sync_metadata(%s)', len(ids) if len(ids) > 10 else ids)
step = 1000 step = 1000
delay = 10 delay = 10
with db.session(): with db.session():
@ -808,6 +815,6 @@ def sync_metadata(ids=None):
i.sync_metadata() i.sync_metadata()
if later: if later:
if state.main and state.tasks: if state.main and state.tasks:
state.main.call_later(delay, lambda: state.tasks.queue('syncmetadata', [later])) state.main.call_later(delay, lambda: state.tasks.queue('syncmetadata', later))
#else: #else:
# logger.debug('sync_metadata done') # logger.debug('sync_metadata done')

View file

@ -369,12 +369,11 @@ class Node(Thread):
return True return True
except: except:
logger.debug('preview download failed %s', url, exc_info=1) logger.debug('preview download failed %s', url, exc_info=1)
return False
elif code == 404: elif code == 404:
pass pass
else: else:
logger.debug('FAILED %s', url) logger.debug('FAILED %s', url)
return False return False
def download_upgrade(self, release): def download_upgrade(self, release):
for module in release['modules']: for module in release['modules']:
@ -422,7 +421,6 @@ class Nodes(Thread):
Thread.__init__(self) Thread.__init__(self)
self.daemon = True self.daemon = True
self.start() self.start()
self.pull()
def cleanup(self): def cleanup(self):
if self._running and self._local: if self._running and self._local:
@ -519,6 +517,8 @@ def update_online():
'id': settings.USER_ID, 'id': settings.USER_ID,
'online': state.online 'online': state.online
}) })
if state.online and state.nodes:
state.nodes.pull()
if settings.OLD_USER_ID and not settings.server.get('migrated_id', False): if settings.OLD_USER_ID and not settings.server.get('migrated_id', False):
from . import directory from . import directory

View file

@ -21,7 +21,7 @@ class Tasks(Thread):
def run(self): def run(self):
import item.scan import item.scan
from item.models import sync_metadata from item.models import sync_metadata, get_preview
from user.models import export_list, update_user_peering from user.models import export_list, update_user_peering
while self.connected: while self.connected:
m = self.q.get() m = self.q.get()
@ -29,22 +29,22 @@ class Tasks(Thread):
try: try:
action, data = m action, data = m
logger.debug('%s start', action) logger.debug('%s start', action)
if action == 'ping': if action == 'export':
trigger_event('pong', data) export_list(data)
elif action == 'getpreview':
get_preview(data)
elif action == 'import': elif action == 'import':
item.scan.run_import(data) item.scan.run_import(data)
elif action == 'export': elif action == 'peering':
export_list(data) update_user_peering(*data)
elif action == 'ping':
trigger_event('pong', data)
elif action == 'scan': elif action == 'scan':
item.scan.run_scan() item.scan.run_scan()
elif action == 'scanimport': elif action == 'scanimport':
item.scan.import_folder() item.scan.import_folder()
elif action == 'peering':
update_user_peering(*data)
elif action == 'syncmetadata': elif action == 'syncmetadata':
if not data: sync_metadata(data)
data = []
sync_metadata(*data)
else: else:
trigger_event('error', {'error': 'unknown action'}) trigger_event('error', {'error': 'unknown action'})
logger.debug('%s done', action) logger.debug('%s done', action)
@ -58,5 +58,6 @@ class Tasks(Thread):
return Thread.join(self) return Thread.join(self)
def queue(self, action, data=None): def queue(self, action, data=None):
logger.debug('%s queued', action)
self.q.put((action, data)) self.q.put((action, data))