Skip to content

Commit 0e2c0ac

Browse files
committed
add run cloud code function
1 parent f9679cb commit 0e2c0ac

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

leancloud/engine/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
from .leanengine import before_delete
1717
from .leanengine import after_delete
1818
from .leanengine import user
19+
from .client import run
1920

2021
__author__ = 'asaka <lan@leancloud.rocks>'
2122

2223

2324
class Engine(object):
2425
def __init__(self, wsgi_app):
26+
self.current_user = user
2527
self.origin_app = wsgi_app
2628
self.cloud_app = context.local_manager.make_middleware(AuthorizationMiddleware(LeanEngineApplication()))
2729

@@ -48,5 +50,6 @@ def __call__(self, environ, start_response):
4850
__all__ = [
4951
'user',
5052
'Engine',
53+
'run',
5154
'LeanEngineError'
5255
]

leancloud/engine/client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding: utf-8
2+
3+
import leancloud
4+
from leancloud import utils
5+
6+
7+
__author__ = 'asaka <lan@leancloud.rocks>'
8+
9+
10+
def run(name, **params):
11+
"""
12+
调用 LeanEngine 上的原生代码
13+
:param name: 需要调用的远程 Cloud Code 的名称
14+
:type name: basestring
15+
:param params: 调用参数
16+
:return: 调用结果
17+
"""
18+
response = leancloud.client.post('/functions/{0}'.format(name), params=params)
19+
content = utils.response_to_json(response)
20+
return utils.decode(None, content)['result']

0 commit comments

Comments
 (0)