abs-utils 0.2.4__tar.gz → 0.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {abs_utils-0.2.4 → abs_utils-0.2.6}/PKG-INFO +1 -1
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/azure_service_bus/event_decorator.py +7 -4
- abs_utils-0.2.6/abs_utils/socket_io/server.py +34 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/pyproject.toml +1 -1
- abs_utils-0.2.4/abs_utils/socket_io/server.py +0 -21
- {abs_utils-0.2.4 → abs_utils-0.2.6}/README.md +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/azure_service_bus/__init__.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/azure_service_bus/azure_service_bus.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/constants/__init__.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/constants/endpoint_constants.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/constants/event_constants.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/logger/__init__.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/logger/logger.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/schemas/__init__.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/schemas/fields_schema/__init__.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/schemas/fields_schema/common_schema.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/schemas/fields_schema/field_schema.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/schemas/libs/__init__.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/schemas/libs/extend_enum.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/schemas/libs/make_optional.py +0 -0
- {abs_utils-0.2.4 → abs_utils-0.2.6}/abs_utils/socket_io/__init__.py +0 -0
|
@@ -4,7 +4,7 @@ from typing import Any, Callable
|
|
|
4
4
|
from .azure_service_bus import AzureServiceBus
|
|
5
5
|
from uuid import uuid4
|
|
6
6
|
import json
|
|
7
|
-
|
|
7
|
+
from ..constants import ON_RECORD_UPDATION
|
|
8
8
|
def azure_event_decorator(event_type: str):
|
|
9
9
|
"""
|
|
10
10
|
A decorator that sends a message to Azure Service Bus after the function execution.
|
|
@@ -44,15 +44,18 @@ def azure_event_decorator(event_type: str):
|
|
|
44
44
|
|
|
45
45
|
# Execute the original function
|
|
46
46
|
result = await func(*args, **kwargs)
|
|
47
|
+
|
|
48
|
+
if event_type != ON_RECORD_UPDATION:
|
|
49
|
+
data = result
|
|
47
50
|
|
|
48
51
|
event_payload = {
|
|
49
52
|
"event_id": str(uuid4()),
|
|
50
53
|
"event_key": event_type,
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"payload_record_id": record_id,
|
|
54
|
+
"collection_name": f"entity_{entity_id}",
|
|
55
|
+
"record_id": record_id,
|
|
54
56
|
"form_id": form_id,
|
|
55
57
|
"payload": data,
|
|
58
|
+
"result": result,
|
|
56
59
|
"user": user,
|
|
57
60
|
}
|
|
58
61
|
# Send message to Azure Service Bus
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import socketio
|
|
2
|
+
from fastapi import FastAPI
|
|
3
|
+
from typing import Callable, Dict, Any
|
|
4
|
+
from functools import wraps
|
|
5
|
+
import asyncio
|
|
6
|
+
from ..logger import setup_logger
|
|
7
|
+
|
|
8
|
+
logger = setup_logger(__name__)
|
|
9
|
+
class SocketIOService:
|
|
10
|
+
def __init__(self, cors_origins: str = "*"):
|
|
11
|
+
self.sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins=cors_origins)
|
|
12
|
+
|
|
13
|
+
def bind_app(self, fastapi_app: FastAPI):
|
|
14
|
+
return socketio.ASGIApp(self.sio, other_asgi_app=fastapi_app)
|
|
15
|
+
|
|
16
|
+
async def emit_to_sid(self, sid: str, event: str, data: Dict[str, Any]):
|
|
17
|
+
await self.sio.emit(event, data, to=sid)
|
|
18
|
+
|
|
19
|
+
async def emit_broadcast(self, event: str, data: Dict[str, Any],namespace:str=None):
|
|
20
|
+
if namespace:
|
|
21
|
+
await self.sio.emit(event, data,namespace=namespace)
|
|
22
|
+
else:
|
|
23
|
+
await self.sio.emit(event, data)
|
|
24
|
+
|
|
25
|
+
async def join_room(self, sid: str, room: str):
|
|
26
|
+
await self.sio.enter_room(sid, room)
|
|
27
|
+
logger.info(f"{sid} joined room {room}")
|
|
28
|
+
|
|
29
|
+
async def leave_room(self, sid: str, room: str):
|
|
30
|
+
await self.sio.leave_room(sid, room)
|
|
31
|
+
logger.info(f"{sid} left room {room}")
|
|
32
|
+
|
|
33
|
+
async def emit_to_room(self, event: str, room: str, data: Dict[str, Any], namespace: str = None):
|
|
34
|
+
await self.sio.emit(event, data, room=room, namespace=namespace)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import socketio
|
|
2
|
-
from fastapi import FastAPI
|
|
3
|
-
from typing import Callable, Dict, Any
|
|
4
|
-
from functools import wraps
|
|
5
|
-
import asyncio
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class SocketIOService:
|
|
9
|
-
def __init__(self, cors_origins: str = "*"):
|
|
10
|
-
self.sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins=cors_origins)
|
|
11
|
-
|
|
12
|
-
def bind_app(self, fastapi_app: FastAPI):
|
|
13
|
-
return socketio.ASGIApp(self.sio, other_asgi_app=fastapi_app)
|
|
14
|
-
|
|
15
|
-
async def emit_to_sid(self, sid: str, event: str, data: Dict[str, Any]):
|
|
16
|
-
"""Emit directly to a specific client."""
|
|
17
|
-
await self.sio.emit(event, data, to=sid)
|
|
18
|
-
|
|
19
|
-
async def emit_broadcast(self, event: str, data: Dict[str, Any]):
|
|
20
|
-
"""Emit to all clients."""
|
|
21
|
-
await self.sio.emit(event, data)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|