Skip to content

Commit

Permalink
MDE/PKFE-46 implemented event handler for export feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mantvydasdeltuva committed Sep 10, 2024
1 parent 845047d commit 3abbb2c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 97 deletions.
1 change: 1 addition & 0 deletions app/back-end/src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
CONSOLE_FEEDBACK_EVENT = "console_feedback"
WORKSPACE_FILE_SAVE_FEEDBACK_EVENT = "workspace_file_save_feedback"
WORKSPACE_UPDATE_FEEDBACK_EVENT = "workspace_update_feedback"
WOKRSPACE_EXPORT_FEEDBACK_EVENT = "workspace_export_feedback"
95 changes: 0 additions & 95 deletions app/back-end/src/events/workspace_event.py

This file was deleted.

81 changes: 81 additions & 0 deletions app/back-end/src/events/workspace_export_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Module for handling Socket.IO events related to workspace file exports.
This module sets up the event handler for the `WOKRSPACE_EXPORT_FEEDBACK_EVENT` event using
Socket.IO. It processes feedback about file export operations and sends appropriate real-time
feedback messages to the user's console based on the status of the export operation.
Imports:
- socketio: The Socket.IO instance for handling real-time communication.
- socketio_emit_to_user_session: Utility function for emitting messages to a user's session.
- WOKRSPACE_EXPORT_FEEDBACK_EVENT: Constant defining the event name for file export feedback.
- CONSOLE_FEEDBACK_EVENT: Constant defining the event name for console feedback.
Functions:
- workspace_export_event_handler: Registers the Socket.IO event handler for file export
feedback.
"""

# pylint: disable=import-error

from src.setup.extensions import socketio
from src.utils.helpers import socketio_emit_to_user_session
from src.constants import WOKRSPACE_EXPORT_FEEDBACK_EVENT, CONSOLE_FEEDBACK_EVENT


def workspace_export_event_handler():
"""
Sets up the event handler for the `WOKRSPACE_EXPORT_FEEDBACK_EVENT` event in Socket.IO.
This function registers an event handler for the `WOKRSPACE_EXPORT_FEEDBACK_EVENT` event,
which is triggered during file export operations in the workspace. The event handler processes
the feedback based on the status of the file export operation and sends appropriate feedback
messages to the user's console.
This function does not return any value. It directly interacts with the Socket.IO event system
to provide real-time feedback to users.
Side Effects:
- Registers the `handle_workspace_export_feedback` function as an event handler for
`WOKRSPACE_EXPORT_FEEDBACK_EVENT` using Socket.IO.
"""

@socketio.on(WOKRSPACE_EXPORT_FEEDBACK_EVENT)
def handle_workspace_export_feedback(data):
"""
Handles the `WOKRSPACE_EXPORT_FEEDBACK_EVENT` event by providing feedback about the
file export operation.
This function listens for Socket.IO events related to workspace file exports and processes
the feedback based on the status provided in the event data. It then sends a message to the
user's console indicating whether the file export was successful or not.
Args:
data (dict): The event data containing feedback about the file export operation.
It should include:
- `status` (str): The status of the file export operation ("success" or "failure").
- `uuid` (str): The unique identifier for the user's session.
- `sid` (str): The session identifier used for emitting real-time feedback.
Emits:
- Success message to the user's console if the status is "success".
- Error message to the user's console if the status is "failure".
Side Effects:
- Sends real-time feedback to the user's console using `socketio_emit_to_user_session`.
"""

if data["status"] == "success":
socketio_emit_to_user_session(
CONSOLE_FEEDBACK_EVENT,
{"type": "succ", "message": "File export completed successfully."},
data["uuid"],
data["sid"],
)
else:
socketio_emit_to_user_session(
CONSOLE_FEEDBACK_EVENT,
{"type": "errr", "message": "File export failed."},
data["uuid"],
data["sid"],
)
4 changes: 2 additions & 2 deletions app/back-end/src/setup/eventer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
from src.setup.extensions import socketio, logger, socket_manager

# Import all event modules here
from src.events.workspace_event import workspace_event_handler
from src.events.workspace_export_event import workspace_export_event_handler


def eventer():
"""
Register all event handlers including connect and disconnect events.
"""
workspace_event_handler(socketio)
workspace_export_event_handler()

@socketio.on("connect")
def handle_connect():
Expand Down

0 comments on commit 3abbb2c

Please sign in to comment.