mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 22:39:43 -04:00
try to lazy init db another way
This commit is contained in:
@@ -88,9 +88,10 @@ encryption = None
|
|||||||
zendesk_client = None
|
zendesk_client = None
|
||||||
redis_store = RedisClient()
|
redis_store = RedisClient()
|
||||||
document_download_client = None
|
document_download_client = None
|
||||||
|
notification_provider_clients = None
|
||||||
|
|
||||||
notification_provider_clients = NotificationProviderClients()
|
# LocalProxy doesn't evaluate the target immediately, but defers
|
||||||
|
# resolution to runtime. So there is no monkeypatching concern.
|
||||||
api_user = LocalProxy(lambda: g.api_user)
|
api_user = LocalProxy(lambda: g.api_user)
|
||||||
authenticated_service = LocalProxy(lambda: g.authenticated_service)
|
authenticated_service = LocalProxy(lambda: g.authenticated_service)
|
||||||
|
|
||||||
@@ -181,10 +182,12 @@ def create_app(application):
|
|||||||
logging.init_app(application)
|
logging.init_app(application)
|
||||||
|
|
||||||
# start lazy initialization for gevent
|
# start lazy initialization for gevent
|
||||||
|
# NOTE: notify_celery and redis_store are safe to construct here
|
||||||
|
# because all entry points (gunicorn_entry.py, run_celery.py) apply
|
||||||
|
# monkey.patch_all() first.
|
||||||
|
# Do NOT access or use them before create_app() is called and don't
|
||||||
|
# call create_app() in multiple places.
|
||||||
|
|
||||||
# Set db engine settings here for now.
|
|
||||||
# They were not being set previous (despite environmental variables with appropriate
|
|
||||||
# sounding names) and were defaulting to low values
|
|
||||||
db = SQLAlchemy(
|
db = SQLAlchemy(
|
||||||
engine_options={
|
engine_options={
|
||||||
"pool_size": config.Config.SQLALCHEMY_POOL_SIZE,
|
"pool_size": config.Config.SQLALCHEMY_POOL_SIZE,
|
||||||
@@ -213,9 +216,7 @@ def create_app(application):
|
|||||||
aws_sns_client.init_app(application)
|
aws_sns_client.init_app(application)
|
||||||
encryption = Encryption()
|
encryption = Encryption()
|
||||||
encryption.init_app(application)
|
encryption.init_app(application)
|
||||||
|
notification_provider_clients = NotificationProviderClients()
|
||||||
# end lazy initialization
|
|
||||||
|
|
||||||
# If a stub url is provided for SES, then use the stub client rather than the real SES boto client
|
# If a stub url is provided for SES, then use the stub client rather than the real SES boto client
|
||||||
email_clients = (
|
email_clients = (
|
||||||
[aws_ses_stub_client]
|
[aws_ses_stub_client]
|
||||||
@@ -225,6 +226,7 @@ def create_app(application):
|
|||||||
notification_provider_clients.init_app(
|
notification_provider_clients.init_app(
|
||||||
sms_clients=[aws_sns_client], email_clients=email_clients
|
sms_clients=[aws_sns_client], email_clients=email_clients
|
||||||
)
|
)
|
||||||
|
# end lazy initialization
|
||||||
|
|
||||||
notify_celery.init_app(application)
|
notify_celery.init_app(application)
|
||||||
redis_store.init_app(application)
|
redis_store.init_app(application)
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import pytest
|
|||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
import application
|
from app import db
|
||||||
from app import create_app, db
|
|
||||||
from app.dao.annual_billing_dao import (
|
from app.dao.annual_billing_dao import (
|
||||||
dao_create_or_update_annual_billing_for_year,
|
dao_create_or_update_annual_billing_for_year,
|
||||||
dao_get_all_free_sms_fragment_limit,
|
dao_get_all_free_sms_fragment_limit,
|
||||||
@@ -19,7 +18,6 @@ from tests.app.db import create_annual_billing, create_service
|
|||||||
|
|
||||||
|
|
||||||
def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service):
|
def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service):
|
||||||
create_app(application)
|
|
||||||
new_limit = 9999
|
new_limit = 9999
|
||||||
year = get_current_calendar_year_start_year()
|
year = get_current_calendar_year_start_year()
|
||||||
dao_create_or_update_annual_billing_for_year(sample_service.id, new_limit, year)
|
dao_create_or_update_annual_billing_for_year(sample_service.id, new_limit, year)
|
||||||
|
|||||||
Reference in New Issue
Block a user