redis added
This commit is contained in:
@@ -5,6 +5,7 @@ from marshmallow import ValidationError
|
||||
import logging
|
||||
from app.api.integrations import KafkaIntegration
|
||||
from app.config import Config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from app.api.integrations import StripeIntegration
|
||||
from flask_mail import Mail, Message
|
||||
@@ -14,6 +15,9 @@ from email.mime.multipart import MIMEMultipart
|
||||
import datetime
|
||||
import jwt
|
||||
import requests
|
||||
import redis
|
||||
import json
|
||||
|
||||
|
||||
class BaseService:
|
||||
TRANSACTION_TYPE = None
|
||||
@@ -33,7 +37,6 @@ class BaseService:
|
||||
logger.info(f"Stripe_Customer ===== : {stripe_customer}")
|
||||
return stripe_customer
|
||||
|
||||
|
||||
@staticmethod
|
||||
def send_completepass_mail(signup_email, pending_uid, pending_id, firstname, lastname):
|
||||
msg_body = f"""
|
||||
@@ -107,7 +110,6 @@ class BaseService:
|
||||
finally:
|
||||
server.quit() # Close the connection
|
||||
|
||||
|
||||
@staticmethod
|
||||
def send_resetpass_mail(signup_email, pending_uid, pending_id, firstname, lastname):
|
||||
|
||||
@@ -125,7 +127,7 @@ class BaseService:
|
||||
{"user": pending_member, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=3330)},
|
||||
BaseService.JWT_SECRET_KEY, algorithm='HS256'
|
||||
)
|
||||
panel_url = BaseService.THIS_SITE_URL #"https://qa-panel.mermsemr.com"
|
||||
panel_url = BaseService.THIS_SITE_URL # "https://qa-panel.mermsemr.com"
|
||||
link_url = str(panel_url) + '/accreset/' + jwt_part
|
||||
|
||||
msg_body = f"""
|
||||
@@ -204,7 +206,6 @@ class BaseService:
|
||||
finally:
|
||||
server.quit() # Close the connection
|
||||
|
||||
|
||||
def send_verify_signup_mail(signup_email, pending_uid, pending_id, firstname, lastname):
|
||||
|
||||
pending_member = {
|
||||
@@ -297,8 +298,6 @@ class BaseService:
|
||||
finally:
|
||||
server.quit() # Close the connection
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def validate_data(cls, data, schema):
|
||||
"""
|
||||
@@ -349,13 +348,13 @@ class BaseService:
|
||||
|
||||
@classmethod
|
||||
def async_send_settings_refresh_to_kafka(cls, settings_data, subscription_uid, topic):
|
||||
KafkaIntegration.send_setting_refresh_request(settings_data = settings_data, subscription_uid =subscription_uid, topic = topic)
|
||||
KafkaIntegration.send_setting_refresh_request(settings_data=settings_data, subscription_uid=subscription_uid,
|
||||
topic=topic)
|
||||
KafkaIntegration.flush()
|
||||
|
||||
|
||||
@classmethod
|
||||
def async_send_to_kafka(cls, loan_data, request_id, topic):
|
||||
KafkaIntegration.send_loan_request(loan_data = loan_data, request_id = request_id, topic = topic)
|
||||
KafkaIntegration.send_loan_request(loan_data=loan_data, request_id=request_id, topic=topic)
|
||||
KafkaIntegration.flush()
|
||||
|
||||
@staticmethod
|
||||
@@ -388,7 +387,53 @@ class BaseService:
|
||||
logger.error(f"An error occurred while get_site_imges_data data: {str(e)}", exc_info=True)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def write_cache_data(cacheSection, cacheId, cacheData):
|
||||
|
||||
try:
|
||||
cacheKey = cacheSection + ':' + cacheId
|
||||
logger.info(f"write_cache_data () key {cacheKey}", exc_info=True)
|
||||
# Define connection parameters and connect
|
||||
r = redis.Redis(host='10.10.33.35', port=6378,
|
||||
password='7f079034e166ecf52d82cbec9876e4dc8a154b0c37248f3fa1734d4eeab938d5',
|
||||
decode_responses=True)
|
||||
|
||||
# Set a key 'foo' with value 'bar'
|
||||
json_string = json.dumps(cacheData, indent=4)
|
||||
r.set(cacheKey, json_string)
|
||||
|
||||
# Verify by getting the value
|
||||
value = r.get(cacheKey)
|
||||
print(f"Value of {cacheKey}: {value}") # Output: Value of 'foo': bar
|
||||
|
||||
# Store a user session as a hash
|
||||
# user_data = {
|
||||
# 'name': 'John',
|
||||
# 'surname': 'Smith',
|
||||
# 'company': 'Redis',
|
||||
# 'age': 29
|
||||
# }
|
||||
# json_string = json.dumps(cacheData, indent=4)
|
||||
#
|
||||
# r.set(cacheSection + ':user-session:123', json_string)
|
||||
|
||||
# r.hset(cacheSection +':user-session:123', mapping=json_string)
|
||||
|
||||
# Retrieve all fields of the hash
|
||||
# session_details = r.hgetall('user-session:123')
|
||||
# print(f"Session details: {session_details}")
|
||||
# Output: Session details: {'name': 'John', 'surname': 'Smith', 'company': 'Redis', 'age': '29'}
|
||||
|
||||
response_data = {
|
||||
"session_details": value,
|
||||
# "product_id": product_id,
|
||||
}
|
||||
|
||||
return response_data
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred while write_cache_data data: {str(e)}", exc_info=True)
|
||||
return None
|
||||
|
||||
#
|
||||
# @classmethod
|
||||
@@ -463,6 +508,3 @@ class BaseService:
|
||||
# }
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -832,7 +832,8 @@ class MyProductsService(BaseService):
|
||||
|
||||
memberSubscription = MembersProducts.get_member_product_by_product_member_id(member_id, product_id)
|
||||
template_images = []
|
||||
template_name=''
|
||||
template_name = ''
|
||||
|
||||
if memberSubscription is not None:
|
||||
custom_template = "" if (
|
||||
memberSubscription.custom_template is None or len(memberSubscription.custom_template)
|
||||
@@ -857,6 +858,7 @@ class MyProductsService(BaseService):
|
||||
blog_product_data = Products.get_product_by_product_id(product_data.blog_product_id)
|
||||
|
||||
settings_items = {}
|
||||
selected_flavor = ''
|
||||
if product_id == "A000001" or product_id == "A000002": ## should be config or data driven not hard coded
|
||||
settings_items = {}
|
||||
|
||||
@@ -876,10 +878,10 @@ class MyProductsService(BaseService):
|
||||
response_data = {
|
||||
"settings_items": settings_items,
|
||||
"member_id": member_id,
|
||||
"subscription_template": subscription_template,
|
||||
"template_name": template_name,
|
||||
"product_subscription_uid": product_subscription_uid,
|
||||
"blog_connect": blogConnect,
|
||||
"subscription_template": str(subscription_template),
|
||||
"template_name": str(template_name),
|
||||
"product_subscription_uid": str(product_subscription_uid),
|
||||
"blog_connect": str(blogConnect),
|
||||
"template_images": template_images
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ class WebContentsService(BaseService):
|
||||
if selectedTemplate:
|
||||
selected_flavor = selectedTemplate.flavor
|
||||
|
||||
|
||||
# BaseService.get_site_imges_data(provision_uid, membersSubResult.primary_server,
|
||||
# membersSubResult.provision_port, selected_flavor)
|
||||
|
||||
@@ -93,6 +94,9 @@ class WebContentsService(BaseService):
|
||||
# The template set up
|
||||
# web_contents_data["web_images"]=[]
|
||||
|
||||
cacheId = str(provision_uid).replace("-", "")
|
||||
BaseService.write_cache_data("WEB_DATA",cacheId, web_contents_data)
|
||||
|
||||
return web_contents_data
|
||||
|
||||
except Exception as e:
|
||||
|
||||
+3
-1
@@ -47,4 +47,6 @@ stripe
|
||||
|
||||
requests
|
||||
|
||||
openai
|
||||
openai
|
||||
|
||||
redis
|
||||
Reference in New Issue
Block a user