mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-08 14:12:27 -05:00
lazy initialize zendesk_client
This commit is contained in:
@@ -99,7 +99,7 @@ aws_sns_client = AwsSnsClient()
|
|||||||
aws_cloudwatch_client = AwsCloudwatchClient()
|
aws_cloudwatch_client = AwsCloudwatchClient()
|
||||||
aws_pinpoint_client = AwsPinpointClient()
|
aws_pinpoint_client = AwsPinpointClient()
|
||||||
encryption = Encryption()
|
encryption = Encryption()
|
||||||
zendesk_client = ZendeskClient()
|
zendesk_client = None
|
||||||
redis_store = RedisClient()
|
redis_store = RedisClient()
|
||||||
document_download_client = DocumentDownloadClient()
|
document_download_client = DocumentDownloadClient()
|
||||||
|
|
||||||
@@ -118,6 +118,16 @@ api_user = LocalProxy(lambda: g.api_user)
|
|||||||
authenticated_service = LocalProxy(lambda: g.authenticated_service)
|
authenticated_service = LocalProxy(lambda: g.authenticated_service)
|
||||||
|
|
||||||
|
|
||||||
|
def get_zendesk_client():
|
||||||
|
global zendesk_client
|
||||||
|
# Our unit tests mock anyway
|
||||||
|
if os.environ.get("NOTIFY_ENVIRONMENT") == "test":
|
||||||
|
return None
|
||||||
|
if zendesk_client is None:
|
||||||
|
raise RuntimeError(f"Celery not initialized zendesk_client: {zendesk_client}")
|
||||||
|
return zendesk_client
|
||||||
|
|
||||||
|
|
||||||
def create_app(application):
|
def create_app(application):
|
||||||
from app.config import configs
|
from app.config import configs
|
||||||
|
|
||||||
@@ -136,7 +146,6 @@ def create_app(application):
|
|||||||
request_helper.init_app(application)
|
request_helper.init_app(application)
|
||||||
db.init_app(application)
|
db.init_app(application)
|
||||||
migrate.init_app(application, db=db)
|
migrate.init_app(application, db=db)
|
||||||
zendesk_client.init_app(application)
|
|
||||||
logging.init_app(application)
|
logging.init_app(application)
|
||||||
aws_sns_client.init_app(application)
|
aws_sns_client.init_app(application)
|
||||||
|
|
||||||
@@ -144,6 +153,12 @@ def create_app(application):
|
|||||||
aws_ses_stub_client.init_app(stub_url=application.config["SES_STUB_URL"])
|
aws_ses_stub_client.init_app(stub_url=application.config["SES_STUB_URL"])
|
||||||
aws_cloudwatch_client.init_app(application)
|
aws_cloudwatch_client.init_app(application)
|
||||||
aws_pinpoint_client.init_app(application)
|
aws_pinpoint_client.init_app(application)
|
||||||
|
|
||||||
|
# start lazy initialization for gevent
|
||||||
|
zendesk_client = ZendeskClient()
|
||||||
|
zendesk_client.init_app(application)
|
||||||
|
# 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]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from flask import current_app
|
|||||||
from sqlalchemy import between, select, union
|
from sqlalchemy import between, select, union
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
|
||||||
from app import db, notify_celery, redis_store, zendesk_client
|
from app import db, get_zendesk_client, notify_celery, redis_store
|
||||||
from app.celery.tasks import (
|
from app.celery.tasks import (
|
||||||
get_recipient_csv_and_template_and_sender_id,
|
get_recipient_csv_and_template_and_sender_id,
|
||||||
process_incomplete_jobs,
|
process_incomplete_jobs,
|
||||||
@@ -44,6 +44,8 @@ from notifications_utils.clients.zendesk.zendesk_client import NotifySupportTick
|
|||||||
|
|
||||||
MAX_NOTIFICATION_FAILS = 10000
|
MAX_NOTIFICATION_FAILS = 10000
|
||||||
|
|
||||||
|
zendesk_client = get_zendesk_client()
|
||||||
|
|
||||||
|
|
||||||
@notify_celery.task(name="run-scheduled-jobs")
|
@notify_celery.task(name="run-scheduled-jobs")
|
||||||
def run_scheduled_jobs():
|
def run_scheduled_jobs():
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ xfail_strict=true
|
|||||||
exclude = venv*,__pycache__,node_modules,cache,migrations,build,sample_cap_xml_documents.py
|
exclude = venv*,__pycache__,node_modules,cache,migrations,build,sample_cap_xml_documents.py
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
# W504 line break after binary operator
|
# W504 line break after binary operator
|
||||||
extend_ignore=B306, W504, E203
|
extend_ignore=B306, W504, E203, F824
|
||||||
|
|
||||||
[isort]
|
[isort]
|
||||||
profile = black
|
profile = black
|
||||||
|
|||||||
Reference in New Issue
Block a user