-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDE/PKFE-46 implemented event handler for export feedback
- Loading branch information
1 parent
845047d
commit 3abbb2c
Showing
4 changed files
with
84 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters