Call fileGet and fileList in async
This commit is contained in:
parent
b6644887bd
commit
bf34d95bc1
1 changed files with 10 additions and 0 deletions
|
@ -37,6 +37,7 @@ class UiWebsocket(object):
|
|||
"channelJoinAllsite", "serverUpdate", "serverPortcheck", "serverShutdown", "certSet", "configSet",
|
||||
"actionPermissionAdd", "actionPermissionRemove"
|
||||
)
|
||||
self.async_commands = ("fileGet", "fileList")
|
||||
|
||||
# Start listener loop
|
||||
def start(self):
|
||||
|
@ -157,6 +158,11 @@ class UiWebsocket(object):
|
|||
permissions.append("ADMIN")
|
||||
return permissions
|
||||
|
||||
def asyncWrapper(self, func):
|
||||
def wrapper(*args, **kwargs):
|
||||
gevent.spawn(func, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
# Handle incoming messages
|
||||
def handleRequest(self, data):
|
||||
req = json.loads(data)
|
||||
|
@ -176,6 +182,10 @@ class UiWebsocket(object):
|
|||
self.response(req["id"], {"error": "Unknown command: %s" % cmd})
|
||||
return
|
||||
|
||||
# Execute in parallel
|
||||
if cmd in self.async_commands:
|
||||
func = self.asyncWrapper(func)
|
||||
|
||||
# Support calling as named, unnamed parameters and raw first argument too
|
||||
if type(params) is dict:
|
||||
func(req["id"], **params)
|
||||
|
|
Loading…
Reference in a new issue