Browse Source

Support sync/async execution

Invoke a function in sync way means the command will wait until the
execution finish. On the contrary, 'sync=false' means user will get
a response before the function is actually invoked. User could get
execution status using execution ID in the response.

Change-Id: I605ea8414f49d44899e0bc8c36b89e48e335d284
changes/17/465917/1
Lingxian Kong 4 years ago
parent
commit
d80f3acf35
  1. 9
      qinling/api/controllers/v1/execution.py
  2. 30
      qinling/rpc.py

9
qinling/api/controllers/v1/execution.py

@ -45,6 +45,7 @@ class ExecutionsController(rest.RestController):
LOG.info("Creating execution. [execution=%s]", params)
function_id = params['function_id']
is_sync = params.get('sync', True)
# Check if the service url is existing.
try:
@ -71,12 +72,14 @@ class ExecutionsController(rest.RestController):
db_model = db_api.create_execution(params)
self.engine_client.create_execution(
db_model.id, function_id, runtime_id, input=params.get('input')
db_model.id, function_id, runtime_id, input=params.get('input'),
is_sync=is_sync
)
updated_db = db_api.get_execution(db_model.id)
if is_sync:
db_model = db_api.get_execution(db_model.id)
return resources.Execution.from_dict(updated_db.to_dict())
return resources.Execution.from_dict(db_model.to_dict())
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(resources.Executions)

30
qinling/rpc.py

@ -147,15 +147,27 @@ class EngineClient(object):
@wrap_messaging_exception
def create_execution(self, execution_id, function_id, runtime_id,
input=None):
return self._client.prepare(topic=self.topic, server=None).call(
ctx.get_ctx(),
'create_execution',
execution_id=execution_id,
function_id=function_id,
runtime_id=runtime_id,
input=input
)
input=None, is_sync=True):
method_client = self._client.prepare(topic=self.topic, server=None)
if is_sync:
return method_client.call(
ctx.get_ctx(),
'create_execution',
execution_id=execution_id,
function_id=function_id,
runtime_id=runtime_id,
input=input
)
else:
method_client.cast(
ctx.get_ctx(),
'create_execution',
execution_id=execution_id,
function_id=function_id,
runtime_id=runtime_id,
input=input
)
@wrap_messaging_exception
def delete_function(self, id, name):

Loading…
Cancel
Save