Compare commits

..

No commits in common. "0529d3fba0c526b1d8b227c78faa82dcee05b26f" and "b34aad1b11fc5488c81e2847b2345f256555ed8f" have entirely different histories.

3 changed files with 10 additions and 48 deletions

4
api.py
View File

@ -112,10 +112,6 @@ async def token_test(request):
return response.json({'ok': False, 'error': 'The token you have provided is not correct.'}, status=401) return response.json({'ok': False, 'error': 'The token you have provided is not correct.'}, status=401)
return response.json({'ok': True, 'message': 'This token is valid :)'}) return response.json({'ok': True, 'message': 'This token is valid :)'})
@bp.get("/ping")
async def ping(request):
return response.text("pong")
@bp.get("/welcome") @bp.get("/welcome")
async def welcome_app(request): async def welcome_app(request):

View File

@ -15,44 +15,30 @@ def killSmptClient():
global sslLock global sslLock
global sslTimer global sslTimer
global smptSender global smptSender
logger.info(f"[SMPT] killSmptClient: Lock status: {self.updating.locked()}")
sslTimer.cancel() sslTimer.cancel()
sslLock.acquire() sslLock.acquire()
exp = None
if(smptSender is not None): if(smptSender is not None):
logger.debug('[SMPT] Closing smpt client') logger.debug('[SMPT] Closing smpt client')
try: smptSender.quit() # it calls close() inside
smptSender.quit() # it calls close() inside
except Exception as e:
exp = e
smptSender = None smptSender = None
sslLock.release() sslLock.release()
if(exp != None):
raise exp
async def openSmptClient(): async def openSmptClient():
global sslLock global sslLock
global sslTimer global sslTimer
global sslContext global sslContext
global smptSender global smptSender
logger.info(f"[SMPT] openSmptClient: Lock status: {self.updating.locked()}")
sslTimer.cancel() sslTimer.cancel()
sslLock.acquire() sslLock.acquire()
exp = None if(smptSender is None):
try: logger.debug('[SMPT] Opening smpt client')
if(smptSender is None): client : smtplib.SMTP = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
logger.debug('[SMPT] Opening smpt client') client.starttls(context=sslContext)
client : smtplib.SMTP = smtplib.SMTP(SMTP_HOST, SMTP_PORT) client.login(SMTP_USER, SMTP_PASSWORD)
client.starttls(context=sslContext) smptSender = client
client.login(SMTP_USER, SMTP_PASSWORD)
smptSender = client
except Exception as e:
exp = e
sslLock.release() sslLock.release()
sslTimer = createTimer() sslTimer = createTimer()
sslTimer.start() sslTimer.start()
if(exp != None):
raise exp
def createTimer(): def createTimer():
return Timer(SMPT_CLIENT_CLOSE_TIMEOUT, killSmptClient) return Timer(SMPT_CLIENT_CLOSE_TIMEOUT, killSmptClient)
@ -65,16 +51,9 @@ async def sendEmail(message : MIMEMultipart):
message['From'] = f'{EMAIL_SENDER_NAME} <{EMAIL_SENDER_MAIL}>' message['From'] = f'{EMAIL_SENDER_NAME} <{EMAIL_SENDER_MAIL}>'
await openSmptClient() await openSmptClient()
logger.debug(f"[SMPT] Sending mail {message['From']} -> {message['to']} '{message['Subject']}'") logger.debug(f"[SMPT] Sending mail {message['From']} -> {message['to']} '{message['Subject']}'")
logger.info(f"[SMPT] sendEmail: Lock status: {self.updating.locked()}")
exp = None
sslLock.acquire() sslLock.acquire()
try: smptSender.sendmail(message['From'], message['to'], message.as_string())
smptSender.sendmail(message['From'], message['to'], message.as_string())
except Exception as e:
exp = e
sslLock.release() sslLock.release()
if(exp != None):
raise exp
def render_email_template(title = "", body = ""): def render_email_template(title = "", body = ""):
tpl = Environment(loader=FileSystemLoader("tpl"), autoescape=False).get_template('email/comunication.html') tpl = Environment(loader=FileSystemLoader("tpl"), autoescape=False).get_template('email/comunication.html')

17
ext.py
View File

@ -367,24 +367,9 @@ class OrderManager:
del cache[code] del cache[code]
orderList.remove(code) orderList.remove(code)
async def fill_cache(self, check_itemsQuestions=False) -> bool: async def fill_cache(self, check_itemsQuestions=False) -> bool:
# Check cache lock # Check cache lock
logger.info(f"[CACHE] Lock status: {self.updating.locked()}")
self.updating.acquire() self.updating.acquire()
ret = False
exp = None
try:
ret = await self.fill_cache_INTERNAL(check_itemsQuestions=check_itemsQuestions)
except Exception as e:
exp = e
self.updating.release()
logger.info(f"[CACHE] Ret status: {ret}. Exp: {exp}")
if(exp != None):
raise exp
return ret
async def fill_cache_INTERNAL(self, check_itemsQuestions=False) -> bool:
start_time = time() start_time = time()
logger.info("[CACHE] Filling cache...") logger.info("[CACHE] Filling cache...")
# Index item's ids # Index item's ids
@ -427,6 +412,8 @@ class OrderManager:
except Exception: except Exception:
logger.error(f"[CACHE] Error while refreshing cache.\n{traceback.format_exc()}") logger.error(f"[CACHE] Error while refreshing cache.\n{traceback.format_exc()}")
success = False success = False
finally:
self.updating.release()
# Apply new cache if there were no errors # Apply new cache if there were no errors
if(success): if(success):