def _wrap(self, function, *args, **kwargs): """ Wrap provided function calling it inside a thread and passing the store to it. """ with transact_lock: start_time = datetime.now() store = Store(create_database(GLSettings.db_uri)) try: if self.instance: result = function(self.instance, store, *args, **kwargs) else: result = function(store, *args, **kwargs) store.commit() except: store.rollback() raise else: return result finally: store.reset() store.close() duration = timedelta_to_milliseconds(datetime.now() - start_time) msg = "Query [%s] executed in %.1fms" % (self.method.__name__, duration) if duration > self.timelimit: log.err(msg) schedule_exception_email(msg) else: log.debug(msg)
def _wrap(self, function, *args, **kwargs): """ Wrap provided function calling it inside a thread and passing the store to it. """ with transact_lock: store = Store(create_database(GLSettings.db_uri)) try: if self.instance: result = function(self.instance, store, *args, **kwargs) else: result = function(store, *args, **kwargs) store.commit() except: store.rollback() raise else: return result finally: store.reset() store.close()