(20250614) Ready for deployment with the UI.

This commit is contained in:
2025-06-14 11:38:42 +05:30
parent 00b5aa0abd
commit d1c0ce24f4
3 changed files with 19 additions and 6 deletions
+17 -4
View File
@@ -47,6 +47,7 @@ from quart import Blueprint, current_app, make_response
# My utils: # My utils:
from utils_v2.string import json from utils_v2.string import json
from utils_v2.date_time import date_time
from utils_v2.api.codes import StatusCodes, HttpCodes from utils_v2.api.codes import StatusCodes, HttpCodes
from utils_v2.api.response import ResponseModel from utils_v2.api.response import ResponseModel
from utils_v2.api.async_quart import ( from utils_v2.api.async_quart import (
@@ -157,6 +158,9 @@ async def set_data(
:return: A standard response structure. :return: A standard response structure.
""" """
# Get the current date-time:
now = date_time.get_current_utc_date_time()
# If an invalid choice was made: # If an invalid choice was made:
if json_type not in JSON_TYPE_INFO.keys(): if json_type not in JSON_TYPE_INFO.keys():
return ResponseModel( return ResponseModel(
@@ -171,14 +175,18 @@ async def set_data(
document = { document = {
"scriptId": inbound_headers["X-Script-Id"], "scriptId": inbound_headers["X-Script-Id"],
"desc": description, "desc": description,
"content": inbound_data "content": inbound_data,
"lastUpdateTs": now
} }
# Make an attempt to set the credentials: # Make an attempt to set the credentials:
success = await current_app.mongo.replace_one( success = await current_app.mongo.update_one(
collection = JSON_TYPE_INFO[json_type]["collection"], collection = JSON_TYPE_INFO[json_type]["collection"],
filter = {"scriptId": inbound_headers["X-Script-Id"]}, filter = {"scriptId": inbound_headers["X-Script-Id"]},
replacement = document, update = {
"$set": document,
"$setOnInsert": {"firstSetTs": now},
},
upsert = True, upsert = True,
raise_exception = True raise_exception = True
) )
@@ -227,6 +235,9 @@ async def get_data(
:return: A standard response structure. :return: A standard response structure.
""" """
# Get the current date-time:
now = date_time.get_current_utc_date_time()
# If an invalid choice was made: # If an invalid choice was made:
if json_type not in JSON_TYPE_INFO.keys(): if json_type not in JSON_TYPE_INFO.keys():
return ResponseModel( return ResponseModel(
@@ -236,9 +247,11 @@ async def get_data(
) )
# Make an attempt to retrieve the credentials: # Make an attempt to retrieve the credentials:
data_json = await current_app.mongo.find_one( data_json = await current_app.mongo.find_one_and_update(
collection = JSON_TYPE_INFO[json_type]["collection"], collection = JSON_TYPE_INFO[json_type]["collection"],
filter = {"scriptId": inbound_headers["X-Script-Id"]}, filter = {"scriptId": inbound_headers["X-Script-Id"]},
update = {"$set": {"lastFetchTs": now}},
return_updated = True,
projection = {"_id": False, "scriptId": False}, projection = {"_id": False, "scriptId": False},
raise_exception = True raise_exception = True
) )
+1 -1
View File
@@ -2,7 +2,7 @@
# Use this to run the microservice without any docker setup. # Use this to run the microservice without any docker setup.
source .venv/bin/activate source .venv/bin/activate
python3 "$(pwd)/api/main.py" --host "0.0.0.0" --port 5102 --script-id "yZqq2NVo" --debug & python3 "$(pwd)/api_v2/main.py" --host "0.0.0.0" --port 5102 --script-id "yZqq2NVo" --debug &
deactivate deactivate
# All done: # All done:
+1 -1
View File
@@ -93,7 +93,7 @@ if __name__ == "__main__":
# Create an instance of the database connector: # Create an instance of the database connector:
my_db = AsyncMongo( my_db = AsyncMongo(
connection_string = constants.MONGO_DATA_CONNECTION_STRING, connection_string = input("Connection String: "),
database_name = constants.MONGO_DATA_DATABASE_NAME, database_name = constants.MONGO_DATA_DATABASE_NAME,
max_connections = 10, max_connections = 10,
debug = True debug = True