def create_execution(engine_client, params): function_id = params['function_id'] is_sync = params.get('sync', True) input = params.get('input') # input in params should be a string. if input: try: params['input'] = json.loads(input) except ValueError: params['input'] = {'__function_input': input} runtime_id = _update_function_db(function_id) params.update({'status': status.RUNNING}) db_model = db_api.create_execution(params) engine_client.create_execution(db_model.id, function_id, runtime_id, input=params.get('input'), is_sync=is_sync) if is_sync: # The execution should already be updated by engine service for sync # execution. db_model = db_api.get_execution(db_model.id) return db_model
def create_execution(engine_client, params): function_id = params['function_id'] is_sync = params.get('sync', True) with db_api.transaction(): func_db = db_api.get_function(function_id) runtime_db = func_db.runtime if runtime_db and runtime_db.status != status.AVAILABLE: raise exc.RuntimeNotAvailableException( 'Runtime %s is not available.' % func_db.runtime_id) # Increase function invoke count, the updated_at field will be also # updated. func_db.count = func_db.count + 1 params.update({'status': status.RUNNING}) db_model = db_api.create_execution(params) engine_client.create_execution(db_model.id, function_id, func_db.runtime_id, input=params.get('input'), is_sync=is_sync) if is_sync: # The execution should already be updated by engine service for sync # execution. db_model = db_api.get_execution(db_model.id) return db_model
def post(self, execution): params = execution.to_dict() LOG.info("Creating execution. [execution=%s]", params) function_id = params['function_id'] # Check if the service url is existing. try: mapping = db_api.get_function_service_mapping(function_id) LOG.debug('Found Service url for function: %s', function_id) func_url = '%s/execute' % mapping.service_url LOG.info('Invoke function %s, url: %s', function_id, func_url) r = requests.post(func_url, data=params.get('input')) params.update({ 'status': 'success', 'output': { 'result': r.json() } }) db_model = db_api.create_execution(params) return resources.Execution.from_dict(db_model.to_dict()) except exc.DBEntityNotFoundError: pass func = db_api.get_function(function_id) runtime_id = func.runtime_id params.update({'status': 'running'}) db_model = db_api.create_execution(params) self.engine_client.create_execution(db_model.id, function_id, runtime_id, input=params.get('input')) updated_db = db_api.get_execution(db_model.id) return resources.Execution.from_dict(updated_db.to_dict())
def create_execution(self, function_id=None, **kwargs): if not function_id: function_id = self.create_function().id execution_params = { 'function_id': function_id, 'project_id': DEFAULT_PROJECT_ID, 'status': status.RUNNING, } execution_params.update(kwargs) execution = db_api.create_execution(execution_params) return execution
def create_execution(engine_client, params): function_id = params['function_id'] is_sync = params.get('sync', True) input = params.get('input') version = params.get('function_version', 0) func_db = db_api.get_function(function_id) runtime_id = func_db.runtime_id # Image type function does not need runtime if runtime_id: runtime_db = db_api.get_runtime(runtime_id) if runtime_db and runtime_db.status != status.AVAILABLE: raise exc.RuntimeNotAvailableException( 'Runtime %s is not available.' % func_db.runtime_id) if version > 0: if func_db.code['source'] != constants.PACKAGE_FUNCTION: raise exc.InputException( "Can not specify version for %s type function." % constants.PACKAGE_FUNCTION) # update version count version_db = db_api.get_function_version(function_id, version) pre_version_count = version_db.count _update_function_version_db(version_db.id, pre_version_count) else: pre_count = func_db.count _update_function_db(function_id, pre_count) # input in params should be a string. if input: try: params['input'] = json.loads(input) except ValueError: params['input'] = {'__function_input': input} params.update({'status': status.RUNNING}) db_model = db_api.create_execution(params) try: engine_client.create_execution(db_model.id, function_id, version, runtime_id, input=params.get('input'), is_sync=is_sync) except exc.QinlingException: # Catch RPC errors for executions: # - for RemoteError in an RPC call, the execution status would be # handled in the engine side; # - for other exceptions in an RPC call or cast, the execution status # would remain RUNNING so we should update it. db_model = db_api.get_execution(db_model.id) if db_model.status == status.RUNNING: db_model = db_api.update_execution(db_model.id, {'status': status.ERROR}) return db_model if is_sync: # The execution should already be updated by engine service for sync # execution. db_model = db_api.get_execution(db_model.id) return db_model