Run msync handlers the same way as sync ones
This commit is contained in:
parent
d2bbb7150c
commit
2ca7c596e3
@ -542,17 +542,7 @@ class SyncApp(object):
|
|||||||
if self.hook_pre_sync is not None:
|
if self.hook_pre_sync is not None:
|
||||||
thread.execute(self.hook_pre_sync, [session])
|
thread.execute(self.hook_pre_sync, [session])
|
||||||
|
|
||||||
# Create a closure to run this operation inside of the thread allocated to this collection
|
result = self._execute_handler_method_in_thread(url, data, session)
|
||||||
def runFunc(col):
|
|
||||||
handler = session.get_handler_for_operation(url, col)
|
|
||||||
func = getattr(handler, url)
|
|
||||||
result = func(**data)
|
|
||||||
col.save()
|
|
||||||
return result
|
|
||||||
runFunc.func_name = url
|
|
||||||
|
|
||||||
# Send to the thread to execute
|
|
||||||
result = thread.execute(runFunc)
|
|
||||||
|
|
||||||
# If it's a complex data type, we convert it to JSON
|
# If it's a complex data type, we convert it to JSON
|
||||||
if type(result) not in (str, unicode):
|
if type(result) not in (str, unicode):
|
||||||
@ -567,10 +557,7 @@ class SyncApp(object):
|
|||||||
if self.hook_post_sync is not None:
|
if self.hook_post_sync is not None:
|
||||||
thread.execute(self.hook_post_sync, [session])
|
thread.execute(self.hook_post_sync, [session])
|
||||||
|
|
||||||
return Response(
|
return result
|
||||||
status='200 OK',
|
|
||||||
content_type='application/json',
|
|
||||||
body=result)
|
|
||||||
|
|
||||||
elif url == 'upload':
|
elif url == 'upload':
|
||||||
thread = session.get_thread()
|
thread = session.get_thread()
|
||||||
@ -604,9 +591,15 @@ class SyncApp(object):
|
|||||||
if url == "begin":
|
if url == "begin":
|
||||||
data['skey'] = session.skey
|
data['skey'] = session.skey
|
||||||
|
|
||||||
return self._execute_handler_method_in_thread(url, data, session)
|
result = self._execute_handler_method_in_thread(url, data, session)
|
||||||
|
|
||||||
return Response(status='200 OK', content_type='text/plain', body='Anki Sync Server')
|
# If it's a complex data type, we convert it to JSON
|
||||||
|
if type(result) not in (str, unicode):
|
||||||
|
result = json.dumps(result)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
return "Anki Sync Server"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _execute_handler_method_in_thread(method_name, keyword_args, session):
|
def _execute_handler_method_in_thread(method_name, keyword_args, session):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user