get preview in tasks
This commit is contained in:
parent
168b293514
commit
5c5c8ac39b
4 changed files with 26 additions and 16 deletions
|
@ -183,7 +183,9 @@ class Changelog(db.Model):
|
|||
i = Item.get(itemid)
|
||||
if i:
|
||||
i.sync_metadata()
|
||||
i.get_preview()
|
||||
if state.tasks:
|
||||
#state.tasks.queue('syncmetadata', [i.id])
|
||||
state.tasks.queue('getpreview', i.id)
|
||||
return True
|
||||
|
||||
def action_removeitem(self, user, timestamp, itemid):
|
||||
|
|
|
@ -791,8 +791,15 @@ def update_sort_table():
|
|||
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):
|
||||
#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
|
||||
delay = 10
|
||||
with db.session():
|
||||
|
@ -808,6 +815,6 @@ def sync_metadata(ids=None):
|
|||
i.sync_metadata()
|
||||
if later:
|
||||
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:
|
||||
# logger.debug('sync_metadata done')
|
||||
|
|
|
@ -369,7 +369,6 @@ class Node(Thread):
|
|||
return True
|
||||
except:
|
||||
logger.debug('preview download failed %s', url, exc_info=1)
|
||||
return False
|
||||
elif code == 404:
|
||||
pass
|
||||
else:
|
||||
|
@ -422,7 +421,6 @@ class Nodes(Thread):
|
|||
Thread.__init__(self)
|
||||
self.daemon = True
|
||||
self.start()
|
||||
self.pull()
|
||||
|
||||
def cleanup(self):
|
||||
if self._running and self._local:
|
||||
|
@ -519,6 +517,8 @@ def update_online():
|
|||
'id': settings.USER_ID,
|
||||
'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):
|
||||
from . import directory
|
||||
|
|
21
oml/tasks.py
21
oml/tasks.py
|
@ -21,7 +21,7 @@ class Tasks(Thread):
|
|||
|
||||
def run(self):
|
||||
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
|
||||
while self.connected:
|
||||
m = self.q.get()
|
||||
|
@ -29,22 +29,22 @@ class Tasks(Thread):
|
|||
try:
|
||||
action, data = m
|
||||
logger.debug('%s start', action)
|
||||
if action == 'ping':
|
||||
trigger_event('pong', data)
|
||||
if action == 'export':
|
||||
export_list(data)
|
||||
elif action == 'getpreview':
|
||||
get_preview(data)
|
||||
elif action == 'import':
|
||||
item.scan.run_import(data)
|
||||
elif action == 'export':
|
||||
export_list(data)
|
||||
elif action == 'peering':
|
||||
update_user_peering(*data)
|
||||
elif action == 'ping':
|
||||
trigger_event('pong', data)
|
||||
elif action == 'scan':
|
||||
item.scan.run_scan()
|
||||
elif action == 'scanimport':
|
||||
item.scan.import_folder()
|
||||
elif action == 'peering':
|
||||
update_user_peering(*data)
|
||||
elif action == 'syncmetadata':
|
||||
if not data:
|
||||
data = []
|
||||
sync_metadata(*data)
|
||||
sync_metadata(data)
|
||||
else:
|
||||
trigger_event('error', {'error': 'unknown action'})
|
||||
logger.debug('%s done', action)
|
||||
|
@ -58,5 +58,6 @@ class Tasks(Thread):
|
|||
return Thread.join(self)
|
||||
|
||||
def queue(self, action, data=None):
|
||||
logger.debug('%s queued', action)
|
||||
self.q.put((action, data))
|
||||
|
||||
|
|
Loading…
Reference in a new issue