simplify app startup

This commit is contained in:
Dobromir Popov
2024-11-12 00:09:09 +02:00
parent 5851af8f80
commit 8c75d1b650
2 changed files with 50 additions and 121 deletions

View File

@ -1,7 +1,7 @@
import asyncio
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import asyncio
from concurrent.futures import ThreadPoolExecutor
from flask import Flask, jsonify, request, render_template, redirect, url_for
# from flask_oauthlib.client import OAuth
@ -23,6 +23,7 @@ def init_app(tr_handler=None):
global on_transaction
on_transaction = tr_handler
app = Flask(__name__, template_folder='../templates', static_folder='../static')
executor = ThreadPoolExecutor(max_workers=10) # Adjust the number of workers as needed
login_manager = LoginManager(app)
login_manager.login_view = 'login'
@ -130,7 +131,7 @@ def init_app(tr_handler=None):
# await process_wh(request_data)
# don't wait for the process to finish
asyncio.create_task(process_wh(request_data ))
executor.submit(asyncio.run, process_wh(request_data))
return jsonify({"status": "OK"}), 200
except Exception as e:
logging.error(f"Error processing webhook: {e}")
@ -138,7 +139,7 @@ def init_app(tr_handler=None):
# Flask route to retry processing the last log
async def process_wh( data):
async def process_wh(data):
global on_transaction
try:
@ -379,4 +380,4 @@ def get_latest_log_file(wh:bool):
utils.log.error(f"Error fetching latest log file: {e}")
return None
export = init_app
export = init_app