From b829d666c90a5d9ec729d224d6198dc9c2abc1b2 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Wed, 16 Feb 2022 12:09:40 -0600 Subject: [PATCH 1/4] fix reports app context --- app/reports.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/app/reports.py b/app/reports.py index 71eb836..80007ac 100644 --- a/app/reports.py +++ b/app/reports.py @@ -37,9 +37,10 @@ def uscore_by_date(date): @scheduler.task("cron", id="gen_item_report", hour=23, timezone="UTC") def gen_item_report(): - try: - current_app.logger.info("Start Item Report Generation") - with scheduler.app.app_context(): + with scheduler.app.app_context(): + try: + current_app.logger.info("Start Item Report Generation") + date = datetime.date.today().strftime('%Y-%m-%d') report = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="items").first() @@ -77,17 +78,18 @@ def gen_item_report(): ) new_report.save() - current_app.logger.info(f"Generated Item Report for {date}") - except Exception as e: - current_app.logger.critical(f"REPORT::ITEMS - {e}") - return + current_app.logger.info(f"Generated Item Report for {date}") + except Exception as e: + current_app.logger.critical(f"REPORT::ITEMS - {e}") + return @scheduler.task("cron", id="gen_currency_report", hour=23, timezone="UTC") def gen_currency_report(): - try: - current_app.logger.info("Start Currency Report Generation") - with scheduler.app.app_context(): + with scheduler.app.app_context(): + try: + current_app.logger.info("Start Currency Report Generation") + date = datetime.date.today().strftime('%Y-%m-%d') report = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="currency").first() @@ -119,17 +121,18 @@ def gen_currency_report(): ) new_report.save() - current_app.logger.info(f"Generated Currency Report for {date}") - except Exception as e: - current_app.logger.critical(f"REPORT::CURRENCY - {e}") - return + current_app.logger.info(f"Generated Currency Report for {date}") + except Exception as e: + current_app.logger.critical(f"REPORT::CURRENCY - {e}") + return @scheduler.task("cron", id="gen_uscore_report", hour=23, timezone="UTC") def gen_uscore_report(): - try: - current_app.logger.info("Start U-Score Report Generation") - with scheduler.app.app_context(): + with scheduler.app.app_context(): + try: + current_app.logger.info("Start U-Score Report Generation") + date = datetime.date.today().strftime('%Y-%m-%d') report = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="uscore").first() @@ -161,7 +164,7 @@ def gen_uscore_report(): ) new_report.save() - current_app.logger.info(f"Generated U-Score Report for {date}") - except Exception as e: - current_app.logger.critical(f"REPORT::U-SCORE - {e}") - return + current_app.logger.info(f"Generated U-Score Report for {date}") + except Exception as e: + current_app.logger.critical(f"REPORT::U-SCORE - {e}") + return From 94411568ce3b5f4039d7fa8800776bdcbcba22b5 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Wed, 16 Feb 2022 13:33:12 -0600 Subject: [PATCH 2/4] fix logging when under gunicorn fis returns in reports --- app/reports.py | 3 +++ wsgi.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/reports.py b/app/reports.py index 80007ac..4b3921e 100644 --- a/app/reports.py +++ b/app/reports.py @@ -47,6 +47,7 @@ def gen_item_report(): # Only one report per day if report != None: current_app.logger.info(f"Item Report Already Generated for {date}") + return char_xmls = CharacterXML.query.join( CharacterInfo, @@ -96,6 +97,7 @@ def gen_currency_report(): # Only one report per day if report != None: current_app.logger.info(f"Currency Report Already Generated for {date}") + return characters = CharacterXML.query.join( CharacterInfo, @@ -139,6 +141,7 @@ def gen_uscore_report(): # Only one report per day if report != None: current_app.logger.info(f"U-Score Report Already Generated for {date}") + return characters = CharacterXML.query.join( CharacterInfo, diff --git a/wsgi.py b/wsgi.py index 7a3b76a..80be7b1 100644 --- a/wsgi.py +++ b/wsgi.py @@ -13,4 +13,13 @@ def make_shell_context(): if __name__ == '__main__': with app.app_context(): app.run(host='0.0.0.0') - +else: + import logging + from loggin.handlers import RotatingFileHandler + gunicorn_logger = logging.getLogger('gunicorn.error') + app.logger.handlers = gunicorn_logger.handlers + file_handler = RotatingFileHandler('nexus_dashboard.log', maxBytes=1024 * 1024 * 100, backupCount=20) + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + file_handler.setFormatter(formatter) + app.logger.addHandler(file_handler) + app.logger.setLevel(gunicorn_logger.level) From 819d51c68a8d26a22bbd2d44badd82ed4dc19688 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Wed, 16 Feb 2022 13:39:55 -0600 Subject: [PATCH 3/4] fix import --- wsgi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsgi.py b/wsgi.py index 80be7b1..90d13e0 100644 --- a/wsgi.py +++ b/wsgi.py @@ -15,7 +15,7 @@ if __name__ == '__main__': app.run(host='0.0.0.0') else: import logging - from loggin.handlers import RotatingFileHandler + from logging.handlers import RotatingFileHandler gunicorn_logger = logging.getLogger('gunicorn.error') app.logger.handlers = gunicorn_logger.handlers file_handler = RotatingFileHandler('nexus_dashboard.log', maxBytes=1024 * 1024 * 100, backupCount=20) From e622c44042d68a133b69ae61e6b51c39f347c3b9 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 19 Feb 2022 21:48:36 -0600 Subject: [PATCH 4/4] fix nulltype object error --- app/luclient.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/luclient.py b/app/luclient.py index d544ce9..25262e3 100644 --- a/app/luclient.py +++ b/app/luclient.py @@ -268,9 +268,13 @@ def register_luclient_jinja_helpers(app): 'select description from Objects where id = ?', [lot_id], one=True - )[0] + ) if desc in ("", None): desc = None + else: + desc = desc[0] + if desc in ("", None): + desc = None if desc: desc = desc.replace('"', "“") return desc