def post(self, body): params = body.to_dict() LOG.info("Creating %s. [params=%s]", self.type, params) db_model = executions.create_execution(self.engine_client, params) return resources.Execution.from_dict(db_model.to_dict())
def invoke(self, id, **kwargs): with db_api.transaction(): # The webhook url can be accessed without authentication, so # insecure is used here webhook_db = db_api.get_webhook(id, insecure=True) function_db = webhook_db.function trust_id = function_db.trust_id project_id = function_db.project_id version = webhook_db.function_version LOG.info('Invoking function %s(version %s) by webhook %s', webhook_db.function_id, version, id) # Setup user context ctx = keystone_utils.create_trust_context(trust_id, project_id) context.set_ctx(ctx) params = { 'function_id': webhook_db.function_id, 'function_version': version, 'sync': False, 'input': json.dumps(kwargs), 'description': constants.EXECUTION_BY_WEBHOOK % id } execution = executions.create_execution(self.engine_client, params) pecan.response.status = 202 return {'execution_id': execution.id}
def post(self, body): ctx = context.get_ctx() acl.enforce('execution:create', ctx) params = body.to_dict() LOG.info("Creating %s. [params=%s]", self.type, params) db_model = executions.create_execution(self.engine_client, params) return resources.Execution.from_db_obj(db_model)
def post(self, body): ctx = context.get_ctx() acl.enforce('execution:create', ctx) params = body.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) db_model = executions.create_execution(self.engine_client, params) return resources.Execution.from_db_obj(db_model)
def handle_job(engine_client): """Execute job task with no db transactions.""" for job in db_api.get_next_jobs(timeutils.utcnow() + timedelta(seconds=3)): job_id = job.id func_id = job.function_id LOG.debug("Processing job: %s, function: %s", job_id, func_id) func_db = db_api.get_function(func_id, insecure=True) trust_id = func_db.trust_id try: # Setup context before schedule job. ctx = keystone_utils.create_trust_context(trust_id, job.project_id) context.set_ctx(ctx) if (job.count is not None and job.count > 0): job.count -= 1 # Job delete/update is done using UPDATE ... FROM ... WHERE # non-locking clause. if job.count == 0: modified = db_api.conditional_update( models.Job, { 'status': status.DONE, 'count': 0 }, { 'id': job_id, 'status': status.RUNNING }, insecure=True, ) else: next_time = jobs.get_next_execution_time( job.pattern, job.next_execution_time) modified = db_api.conditional_update( models.Job, { 'next_execution_time': next_time, 'count': job.count }, { 'id': job_id, 'next_execution_time': job.next_execution_time }, insecure=True, ) if not modified: LOG.warning( 'Job %s has been already handled by another periodic ' 'task.', job_id) continue LOG.debug("Starting to execute function %s by job %s", func_id, job_id) params = { 'function_id': func_id, 'input': job.function_input, 'sync': False, 'description': constants.EXECUTION_BY_JOB % job_id } executions.create_execution(engine_client, params) except Exception: LOG.exception("Failed to process job %s", job_id) finally: context.set_ctx(None)