def before_request(): """Save time before each request""" timestamp = strftime('[%Y-%b-%d %H:%M]') g.request_start_time = time.time() content_size = request.content_length if content_size and content_size > (15 * 1000000): logger.error( f'large content size: {request.content_length / 1000000} MB') logger.debug(f'time: {timestamp} uri: {request.full_path}')
def run_on_start(): repo = git.Repo(search_parent_directories=True) sha = repo.head.object.hexsha if settings.IS_MIX_PANEL: mp_tread = mix_panel.MixPanelThread() mp_tread.start() logger.info('initializing app') logger.error(f'THIS IS NOT AN ERROR: Server Deployed SHA : {sha}')
def after_request(response): """Calculate and log execution time""" request_time = time.time() - g.request_start_time if request_time > 0.4: logger.error( f'uri: {request.full_path} request_time: {"%.5fs" % request_time} data: {request.data}' ) else: logger.info( f'uri: {request.full_path} request_time: {"%.5fs" % request_time}') return response
def get_distance(pubsub: PubSub) -> float: pubsub.subscribe("subsystem.sonar.measurement", ignore_subscribe_messages=True) timeout = 0.5 start = time.time() while cycle([True]): if time.time() - start > timeout: logger.error("Unable to get sonar measurement!!") raise NoSonarException("Unable to get sonar measurement") redis_message = pubsub.get_message() if redis_message is not None: pubsub.unsubscribe("subsystem.sonar.measurement") message = json.loads(redis_message['data']) return float(message) sleep(0.01)
def after_request(response): """Calculate and log execution time""" request_time = time.time() - g.request_start_time if not settings.IS_MIX_PANEL: time_limit = 0.4 else: time_limit = 1.5 if request_time > time_limit: logger.error( f'method:{request.method} uri: {request.full_path} request_time: {"%.5fs" % request_time}' ) else: logger.info( f'method:{request.method} uri: {request.full_path} request_time: {"%.5fs" % request_time}' ) return response
def run_on_start(): repo = git.Repo(search_parent_directories=True) sha = repo.head.object.hexsha logger.info('initializing app') logger.error(f'THIS IS NOT AN ERROR: Server Deployed SHA : {sha}')