mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-12 09:58:04 -04:00
Remove SocketIO (#2019)
* Remove SocketIO We have tried a few times to enable SocketIO in our app and it has been a challenge each step of the way, and now there is a dependency incompatibility it seems. Given that we are in maintenance mode with the applicaiton currently and hve different plans for the interface, we are removing this dependency. Signed-off-by: Carlo Costino <carlo.costino@gsa.gov> * Remove more unused code and address Flake8 warnings Signed-off-by: Carlo Costino <carlo.costino@gsa.gov> * Revert changes to fix test Signed-off-by: Carlo Costino <carlo.costino@gsa.gov> --------- Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
@@ -19,7 +19,6 @@ from flask import (
|
||||
)
|
||||
from flask.ctx import has_app_context
|
||||
from flask_migrate import Migrate
|
||||
from flask_socketio import SocketIO
|
||||
from flask_sqlalchemy import SQLAlchemy as _SQLAlchemy
|
||||
from sqlalchemy import event
|
||||
from werkzeug.exceptions import HTTPException as WerkzeugHTTPException
|
||||
@@ -101,15 +100,6 @@ zendesk_client = None
|
||||
redis_store = RedisClient()
|
||||
document_download_client = None
|
||||
|
||||
socketio = SocketIO(
|
||||
cors_allowed_origins=[
|
||||
config.Config.ADMIN_BASE_URL,
|
||||
],
|
||||
message_queue=config.Config.REDIS_URL,
|
||||
logger=True,
|
||||
engineio_logger=True,
|
||||
)
|
||||
|
||||
notification_provider_clients = NotificationProviderClients()
|
||||
|
||||
api_user = LocalProxy(lambda: g.api_user)
|
||||
@@ -158,11 +148,6 @@ def create_app(application):
|
||||
application.config["NOTIFY_APP_NAME"] = application.name
|
||||
init_app(application)
|
||||
|
||||
socketio.init_app(application)
|
||||
|
||||
from app.socket_handlers import register_socket_handlers
|
||||
|
||||
register_socket_handlers(socketio)
|
||||
request_helper.init_app(application)
|
||||
db.init_app(application)
|
||||
logging.init_app(application)
|
||||
|
||||
@@ -26,11 +26,9 @@ from werkzeug.datastructures import MultiDict
|
||||
from app import create_uuid, db
|
||||
from app.dao.dao_utils import autocommit
|
||||
from app.dao.inbound_sms_dao import Pagination
|
||||
from app.dao.jobs_dao import dao_get_job_by_id
|
||||
from app.enums import KeyType, NotificationStatus, NotificationType
|
||||
from app.models import FactNotificationStatus, Notification, NotificationHistory
|
||||
from app.utils import (
|
||||
emit_job_update_summary,
|
||||
escape_special_characters,
|
||||
get_midnight_in_utc,
|
||||
midnight_n_days_ago,
|
||||
@@ -897,19 +895,6 @@ def dao_update_delivery_receipts(receipts, delivered):
|
||||
f"#loadtestperformance batch update query time: \
|
||||
updated {len(receipts)} notification in {elapsed_time} ms"
|
||||
)
|
||||
job_ids = (
|
||||
db.session.execute(
|
||||
select(Notification.job_id).where(
|
||||
Notification.message_id.in_(id_to_carrier.keys())
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
for job_id in set(job_ids):
|
||||
job = dao_get_job_by_id(job_id)
|
||||
emit_job_update_summary(job)
|
||||
|
||||
|
||||
def dao_close_out_delivery_receipts():
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
from flask import current_app, request
|
||||
from flask_socketio import join_room, leave_room
|
||||
|
||||
|
||||
def register_socket_handlers(socketio):
|
||||
@socketio.on("connect")
|
||||
def on_connect():
|
||||
current_app.logger.info(
|
||||
f"Socket {request.sid} connected from {request.environ.get('HTTP_ORIGIN')}"
|
||||
)
|
||||
return True
|
||||
|
||||
@socketio.on("disconnect")
|
||||
def on_disconnect():
|
||||
current_app.logger.info(f"Socket {request.sid} disconnected")
|
||||
|
||||
@socketio.on("join")
|
||||
def on_join(data): # noqa: F401
|
||||
room = data.get("room")
|
||||
join_room(room)
|
||||
current_app.logger.info(f"Socket {request.sid} joined room {room}")
|
||||
|
||||
@socketio.on("leave")
|
||||
def on_leave(data): # noqa: F401
|
||||
room = data.get("room")
|
||||
leave_room(room)
|
||||
current_app.logger.info(f"Socket {request.sid} left room {room}")
|
||||
14
app/utils.py
14
app/utils.py
@@ -146,20 +146,6 @@ def debug_not_production(msg):
|
||||
current_app.logger.info(msg)
|
||||
|
||||
|
||||
def emit_job_update_summary(job):
|
||||
from app import socketio
|
||||
|
||||
socketio.emit(
|
||||
"job_updated",
|
||||
{
|
||||
"job_id": str(job.id),
|
||||
"job_status": job.job_status,
|
||||
"notification_count": job.notification_count,
|
||||
},
|
||||
room=f"job-{job.id}",
|
||||
)
|
||||
|
||||
|
||||
def is_suspicious_input(input_str):
|
||||
if not isinstance(input_str, str):
|
||||
return False
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import print_function
|
||||
from flask import Flask # noqa
|
||||
from werkzeug.serving import WSGIRequestHandler # noqa
|
||||
|
||||
from app import create_app, socketio # noqa
|
||||
from app import create_app # noqa
|
||||
|
||||
WSGIRequestHandler.version_string = lambda self: "SecureServer"
|
||||
|
||||
|
||||
1805
poetry.lock
generated
1805
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -74,7 +74,6 @@ itsdangerous = "^2.2.0"
|
||||
jinja2 = "^3.1.6"
|
||||
redis = "^5.0.8"
|
||||
requests = "^2.32.5"
|
||||
flask-socketio = "^5.5.1"
|
||||
virtualenv = "^20.34.0"
|
||||
marshmallow-enum = "^1.5.1"
|
||||
awscli = "^1.40.36"
|
||||
|
||||
@@ -1451,23 +1451,12 @@ def test_update_delivery_receipts(mocker):
|
||||
mock_update.where.return_value = mock_where
|
||||
mock_where.values.return_value = mock_values
|
||||
|
||||
FakeJob = type(
|
||||
"FakeJob",
|
||||
(object,),
|
||||
{"id": "job-123", "notification_count": 5, "job_status": "delivered"},
|
||||
)
|
||||
|
||||
fake_result = MagicMock()
|
||||
fake_result.scalars.return_value.all.return_value = ["job-1", "job-2"]
|
||||
fake_result.scalars.return_value.one.return_value = FakeJob()
|
||||
|
||||
mock_session.execute.side_effect = lambda *args, **kwargs: fake_result
|
||||
mock_session.execute.return_value = None
|
||||
with patch("app.dao.notifications_dao.update", return_value=mock_update):
|
||||
dao_update_delivery_receipts(receipts, delivered)
|
||||
mock_update.where.assert_called_once()
|
||||
mock_where.values.assert_called_once()
|
||||
mock_session.execute.assert_any_call(mock_values)
|
||||
assert mock_session.execute.call_count == 4
|
||||
mock_session.execute.assert_called_once_with(mock_values)
|
||||
mock_session.commit.assert_called_once()
|
||||
|
||||
args, kwargs = mock_where.values.call_args
|
||||
|
||||
Reference in New Issue
Block a user