(202501001) New Socket.IO system started with provision for namespaces and more.

This commit is contained in:
2025-10-01 17:00:09 +05:30
parent c21ec7ba42
commit acb709667b
4 changed files with 219 additions and 27 deletions
+15 -14
View File
@@ -35,6 +35,9 @@ import sys
sys.path.append(".")
sys.path.append("..")
# For system-level activities:
import os
# My utils:
from utils_v2.string import regex
from utils_v2.queue.kafka.controllers.async_kafka import ConsumerKafka, get_ssl_context
@@ -104,20 +107,18 @@ def origin_is_allowed(origin: str, app_state: AppState) -> bool:
async def init(
script_id: str,
debug: bool,
app_state: AppState,
):
"""
To initialize all credentials, instances, and connectivity for this whole script.
:param script_id: The id to use to load cred and data from the internal service.
:param debug: Whether, or not, you would like to print the debug messages.
:param app_state: The app's state with all the shared variables.
:return: True if initialized successfully, else False.
"""
# Basic stuff:
if debug: app_state.printer.enable()
app_state.SCRIPT_ID = os.environ["SCRIPT_ID"]
app_state.debug = True if str(os.environ["DEBUG"]).lower().find("true") >= 0 else False
app_state.printer("Initializing.")
# ┏┓ • •
@@ -137,9 +138,9 @@ async def init(
if response.status_code not in [200]:
print("FATAL: ALLOWED ORIGINS NOT FETCHED!")
return False
ALLOWED_ORIGINS = [origin["domain"] for origin in response.json().get("data", {}).get("rs2", [])]
app_state.printer(ALLOWED_ORIGINS)
if len(ALLOWED_ORIGINS) < 1:
app_state.ALLOWED_ORIGINS = [origin["domain"] for origin in response.json().get("data", {}).get("rs2", [])]
app_state.printer(app_state.ALLOWED_ORIGINS)
if len(app_state.ALLOWED_ORIGINS) < 1:
print("FATAL: ALLOWED ORIGINS IS EMPTY!")
return False
@@ -150,7 +151,7 @@ async def init(
# Get the script credentials:
response = await app_state.http_client.get(
url = r"https://nexcom.ditscentre.in/internal/cred/get",
headers = {"X-Script-Id": script_id}
headers = {"X-Script-Id": app_state.SCRIPT_ID}
)
if response.status_code not in [200]:
print("FATAL: SCRIPT CREDENTIALS LOADING FAILED!")
@@ -160,7 +161,7 @@ async def init(
# Get the script data:
response = await app_state.http_client.get(
url = r"https://nexcom.ditscentre.in/internal/data/get",
headers = {"X-Script-Id": script_id}
headers = {"X-Script-Id": app_state.SCRIPT_ID}
)
if response.status_code not in [200]:
print("FATAL: SCRIPT DATA LOADING FAILED!")
@@ -186,7 +187,7 @@ async def init(
key_file = consumer_creds["config"].get("keyFile"),
),
serializer = JSONSerializer(),
debug = debug
debug = app_state.debug
)
if not await app_state.kafka_consumer.connect():
print("FATAL: KAFKA CONSUMER NOT CREATED!")
@@ -198,10 +199,10 @@ async def init(
# ┛┗┗ ┗┻┗┛ ┗┛┗┻┗┛┗┗
app_state.redis_cache = AsyncRedisCache(
connection_string = script_cred["redisCache"]["general"]["sentinelJson"],
# connection_string = script_cred["redisCache"]["general"]["connectionString"],
# connection_string = script_cred["redisCache"]["general"]["sentinelJson"],
connection_string = script_cred["redisCache"]["general"]["connectionString"],
# serializer = JSONSerializer(),
debug = debug,
debug = app_state.debug,
debug_prefix = "General Cache | "
)
if not await app_state.redis_cache.connect():