installed prisma for py

This commit is contained in:
Dobromir Popov
2024-11-06 12:54:32 +02:00
parent 3dd7e315c7
commit efbe12f173
8 changed files with 53 additions and 22 deletions

View File

@ -405,6 +405,15 @@ app = init_app()
# Convert Flask app to ASGI
asgi_app = WsgiToAsgi(app)
async def restartable_task(task_func, *args, **kwargs):
while True:
try:
await task_func(*args, **kwargs)
except Exception as e:
logging.error(f"Error in task {task_func.__name__}: {e}")
await telegram_utils.send_telegram_message(f"Error in task {task_func.__name__}: {e}")
await asyncio.sleep(5) # Wait before retrying
async def main():
global bot, PROCESSING_LOG, pk
@ -413,10 +422,11 @@ async def main():
await telegram_utils.send_telegram_message("Solana Agent Started. Connecting to mainnet...")
# Start the log processor
asyncio.create_task(watch_for_new_logs())
asyncio.create_task(restartable_task(watch_for_new_logs))
# process_transaction
if DO_WATCH_WALLET:
asyncio.create_task(restartable_task(SAPI.wallet_watch_loop))
await SAPI.wallet_watch_loop()
def run_asyncio_tasks():

View File

@ -1,10 +1,11 @@
import os
import asyncio
from pathlib import Path
from .storage import store_transaction
from .storage import store_transaction, prisma_client
from .SolanaAPI import SolanaAPI
LOG_DIRECTORY = "path/to/log/directory"
FILE_MASK = "*.log"
LOG_DIRECTORY = "logs"
FILE_MASK = "wh_*.json"
async def process_log_file(file_path):
# Read the file and extract transaction data
@ -22,8 +23,18 @@ async def process_log_file(file_path):
solana_signature = "extracted_solana_signature"
details = {}
# Store the transaction
await store_transaction(wallet_id, transaction_type, sell_currency, sell_amount, sell_value, buy_currency, buy_amount, buy_value, solana_signature, details)
# Process the webhook data
solana_api = SolanaAPI()
transaction_data = await solana_api.process_wh(data)
# Check if the transaction already exists
existing_transaction = await prisma_client.transaction.find_first(
where={'solana_signature': solana_signature}
)
if not existing_transaction:
# Store the transaction if it doesn't exist
await store_transaction(wallet_id, transaction_type, sell_currency, sell_amount, sell_value, buy_currency, buy_amount, buy_value, solana_signature, details)
# Rename the file to append '_saved'
new_file_path = file_path.with_name(file_path.stem + "_saved" + file_path.suffix)

View File

@ -355,3 +355,5 @@ def get_latest_log_file(wh:bool):
except Exception as e:
utils.log.error(f"Error fetching latest log file: {e}")
return None
export = init_app

View File

@ -32,11 +32,12 @@ pip-compile requirements.in
# Optionally, update your environment
# pip-sync requirements.txt
echo "Requirements have been updated in requirements.txt"
prisma on py:
//#python -m prisma generate
pip install -U prisma
prisma db push
max ammount on FATGF gives error:
ERROR:error_logger:<b>Swap Follow Error:</b>
Program log: Instruction: Transfer", "Program log: Error: insufficient funds", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4300 of 1363889 compute units"
# PROD deployment:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker app:asgi_app --bind 0.0.0.0:3001 --log-level info