Skip to content

Commit

Permalink
Merge pull request #156 from x-atlas-consortia/karlburke/flask3updates
Browse files Browse the repository at this point in the history
Updates for Flask 3 and associated dependencies, including replacing …
  • Loading branch information
yuanzhou authored Jul 20, 2024
2 parents ce28df7 + c4db2b9 commit d409b90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
39 changes: 20 additions & 19 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@

# Use `getLogger()` instead of `getLogger(__name__)` to apply the config to the root logger
# will be inherited by the sub-module loggers
logger = logging.getLogger()
try:
logger = logging.getLogger()
logger.info(f"Starting. Logger initialized, with logging level {logger.level}")
except Exception as e:
print("Error opening log file during startup")
print(str(e))

# Specify the absolute path of the instance folder and use the config file relative to the instance path
app = Flask(__name__, instance_path=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'instance'),
Expand All @@ -31,28 +36,24 @@
# Use configuration from instance/app.cfg, deployed per-app from examples in the repository.
try:
app.config.from_pyfile('app.cfg')
logger.info("Application initialized from instance/app.cfg")
except Exception as e:
logger.critical(f"Unable to initialize application from instance/app.cfg due to e='{str(e)}'")
raise Exception("Failed to get configuration from instance/app.cfg")

worker = None

@app.before_first_request
def init():
global worker
try:
logger.info("started")
except Exception as e:
print("Error opening log file during startup")
print(str(e))

try:
worker = UUIDWorker(app_config=app.config)
logger.info("initialized")
except Exception as e:
print("Error during startup.")
print(str(e))
logger.error(e, exc_info=True)
print("Check the log file for further information: " + LOG_FILE_NAME)
try:
worker = UUIDWorker(app_config=app.config)
logger.info("UUIDWorker instantiated using app.cfg setting.")
except Exception as e:
logger.critical(f"Unable to instantiate a UUIDWorker during startup.")
print("Error instantiating a UUIDWorker during startup.")
print(str(e))
logger.error(e, exc_info=True)
print("Check the log file for further information: " + LOG_FILE_NAME)

logger.info('')
logger.info('')

@app.route('/', methods=['GET'])
def index():
Expand Down
2 changes: 1 addition & 1 deletion src/instance/app.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DB_PASSWORD = '123'
APP_ID_PREFIX = 'HBM'
#Set to the ID used in the entity-api
APP_ID = 'hubmap_id'
APP_BASE_ID = 'base_id'
APP_BASE_ID = 'hubmap_base_id'

BASE_DIR_TYPES = ['DATA_UPLOAD', 'INGEST_PORTAL_UPLOAD']
# Entity types which have a uuids_attributes.BASE_ID associated with them
Expand Down
8 changes: 4 additions & 4 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Flask==2.1.3
Flask==3.0.3

# Flask 2.1.3 installs the latest Werkzeug==3.0.0 (released on 9/30/2023) and causing import issues
# Use a pinned version 2.3.7 (the latest release before 3.0.0) to mitigate temporaryly
# Will upgrade Flask to newer version later on across all APIs. 10/3/2023 - Zhou
Werkzeug==2.3.7
Werkzeug==3.0.3

# To match the AWS RDS MySQL server 8.0.23, returned by the SELECT VERSION() query.
mysql-connector-python==8.0.23

# The commons package requires requests>=2.22.0
requests==2.25.1
requests==2.32.3

# Use the published package from PyPI as default
# Use the branch name of commons from github for testing new changes made in commons
# Default is master branch specified in docker-compose.yml if not set
# git+https://github.com/hubmapconsortium/commons.git@${COMMONS_BRANCH}#egg=hubmap-commons
hubmap-commons==2.1.12
hubmap-commons==2.1.15
2 changes: 1 addition & 1 deletion src/uuid_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def __init__(self, app_config=None):

if 'LARGE_RESPONSE_THRESHOLD' not in app_config \
or not isinstance(app_config['LARGE_RESPONSE_THRESHOLD'], int) \
or int(app_config['LARGE_RESPONSE_THRESHOLD'] > 9999999):
or app_config['LARGE_RESPONSE_THRESHOLD'] > 10*(2**20)-1:
self.logger.error(f"There is a problem with the LARGE_RESPONSE_THRESHOLD setting in app.cfg."
f" Defaulting to small value so noticed quickly.")
large_response_threshold = 5000000
Expand Down

0 comments on commit d409b90

Please sign in to comment.