def post(self, job): """Creates a new job.""" params = job.to_dict() if not POST_REQUIRED.issubset(set(params.keys())): raise exc.InputException( 'Required param is missing. Required: %s' % POST_REQUIRED) # Check the input params. first_time, next_time, count = jobs.validate_job(params) LOG.info("Creating %s, params: %s", self.type, params) with db_api.transaction(): db_api.get_function(params['function_id']) values = { 'name': params.get('name'), 'pattern': params.get('pattern'), 'first_execution_time': first_time, 'next_execution_time': next_time, 'count': count, 'function_id': params['function_id'], 'function_input': params.get('function_input') or {}, 'status': status.RUNNING } db_job = db_api.create_job(values) return resources.Job.from_dict(db_job.to_dict())
def post(self, job): """Creates a new job.""" params = job.to_dict() if not (params.get("function_id") or params.get("function_alias")): raise exc.InputException( 'Either function_alias or function_id must be provided.') LOG.info("Creating %s, params: %s", self.type, params) # Check the input params. first_time, next_time, count = jobs.validate_job(params) version = params.get('function_version', 0) function_alias = params.get('function_alias') if function_alias: # Check if the alias exists. db_api.get_function_alias(function_alias) else: # Check the function(version) exists. db_api.get_function(params['function_id']) if version > 0: # Check if the version exists. db_api.get_function_version(params['function_id'], version) values = { 'name': params.get('name'), 'pattern': params.get('pattern'), 'first_execution_time': first_time, 'next_execution_time': next_time, 'count': count, 'function_alias': function_alias, 'function_id': params.get("function_id"), 'function_version': version, 'function_input': params.get('function_input'), 'status': status.RUNNING } db_job = db_api.create_job(values) return resources.Job.from_db_obj(db_job)
def post(self, job): """Creates a new job.""" params = job.to_dict() if not POST_REQUIRED.issubset(set(params.keys())): raise exc.InputException( 'Required param is missing. Required: %s' % POST_REQUIRED) # Check the input params. first_time, next_time, count = jobs.validate_job(params) LOG.info("Creating %s, params: %s", self.type, params) with db_api.transaction(): db_api.get_function(params['function_id']) values = { 'name': params.get('name'), 'pattern': params.get('pattern'), 'first_execution_time': first_time, 'next_execution_time': next_time, 'count': count, 'function_id': params['function_id'], 'function_input': params.get('function_input') or {}, 'status': status.RUNNING } if cfg.CONF.pecan.auth_enable: values['trust_id'] = keystone_util.create_trust().id try: db_job = db_api.create_job(values) except Exception: # Delete trust before raising exception. keystone_util.delete_trust(values.get('trust_id')) raise return resources.Job.from_dict(db_job.to_dict())