Fix bot & batcher
This commit is contained in:
parent
572980f469
commit
8bfd46988f
|
@ -1,7 +1,10 @@
|
|||
import asyncio
|
||||
|
||||
from app.src.config import PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, PG_DB
|
||||
from pathlib import Path
|
||||
from starlette.requests import Request
|
||||
import asyncpg
|
||||
import logging
|
||||
from asyncpg_trek import plan, execute, Direction
|
||||
from asyncpg_trek.asyncpg import AsyncpgBackend
|
||||
|
||||
|
@ -9,9 +12,17 @@ from asyncpg_trek.asyncpg import AsyncpgBackend
|
|||
DB_URL = f'postgresql://{PG_USER}:{str(PG_PASSWORD)}@{PG_HOST}:{PG_PORT}/{PG_DB}'
|
||||
MIGRATIONS_DIR = Path(__file__).parent.resolve() / "migrations"
|
||||
|
||||
logger = logging.getLogger("uvicorn")
|
||||
|
||||
async def connect_pg() -> asyncpg.Pool:
|
||||
return await asyncpg.create_pool(DB_URL)
|
||||
while True:
|
||||
try:
|
||||
logger.info(DB_URL)
|
||||
pg_conn = await asyncpg.create_pool(DB_URL)
|
||||
return pg_conn
|
||||
except OSError:
|
||||
logger.info("Postgres is unavailable - sleeping")
|
||||
await asyncio.sleep(2)
|
||||
|
||||
|
||||
async def get_pg(request: Request) -> asyncpg.Connection:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
import aio_pika
|
||||
import logging
|
||||
from starlette.requests import Request
|
||||
from aio_pika.abc import AbstractRobustConnection
|
||||
|
||||
|
@ -7,6 +8,7 @@ from ..config import RMQ_HOST, RMQ_PORT, RMQ_USER, RMQ_PASSWORD
|
|||
|
||||
|
||||
fqdn = f'amqp://{RMQ_USER}:{str(RMQ_PASSWORD)}@{RMQ_HOST}:{RMQ_PORT}/'
|
||||
logger = logging.getLogger("uvicorn")
|
||||
|
||||
async def get_connection() -> AbstractRobustConnection:
|
||||
while True:
|
||||
|
@ -14,6 +16,7 @@ async def get_connection() -> AbstractRobustConnection:
|
|||
conn = await aio_pika.connect_robust(fqdn)
|
||||
return conn
|
||||
except ConnectionError:
|
||||
logger.info("RabbitMQ is unavailable - sleeping")
|
||||
await asyncio.sleep(2)
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from typing import Callable
|
|||
SETTING_QUEUE_NAME = "settings"
|
||||
|
||||
async def consume_setting_updates(set_setting_func: Callable[[str, decimal.Decimal], None], chan: aio_pika.abc.AbstractChannel):
|
||||
queue = await chan.get_queue(SETTING_QUEUE_NAME)
|
||||
queue = await chan.declare_queue(SETTING_QUEUE_NAME)
|
||||
|
||||
async with queue.iterator() as queue_iter:
|
||||
async for msg in queue_iter:
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import logging
|
||||
from aiogram import Bot, types
|
||||
from aiogram import Dispatcher
|
||||
from create_bot import bot, token, WEBHOOK_URL
|
||||
from handlers.register_handlers import register_all_handlers
|
||||
from aiogram import Bot, Dispatcher, Router, types
|
||||
from aiogram.fsm.storage.memory import MemoryStorage
|
||||
from create_bot import bot, WEBHOOK_URL
|
||||
from handlers.register_handlers import register_all_handlers
|
||||
from loguru import logger
|
||||
|
||||
dp = Dispatcher(bot, storage=MemoryStorage())
|
||||
dp = Dispatcher(storage=MemoryStorage())
|
||||
|
||||
logger.add("logs.log", format = "{time} | {module} : {function} | {level} | {message}", level = "INFO", rotation = "1 week", compression = "zip")#, serialize = True)
|
||||
|
||||
|
@ -19,7 +17,9 @@ async def on_startup():
|
|||
drop_pending_updates=True
|
||||
)
|
||||
|
||||
register_all_handlers(dp)
|
||||
router = Router()
|
||||
register_all_handlers(router)
|
||||
dp.include_router(router)
|
||||
|
||||
|
||||
async def on_shutdown():
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
import asyncio
|
||||
from aiogram import Bot, Dispatcher, types
|
||||
import re
|
||||
import os
|
||||
import time
|
||||
import shutil
|
||||
import random
|
||||
from create_bot import bot, request_url, important_message, url, token, bucket_name, username, password, endpoint_url
|
||||
from req import check_register
|
||||
import urllib.request
|
||||
from messages import get_main_menu_message
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.fsm.state import State, StatesGroup
|
||||
from aiogram.enums import ParseMode
|
||||
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo
|
||||
|
||||
from loguru import logger
|
||||
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
|
||||
def get_answer_keyboard():
|
||||
button1 = InlineKeyboardButton(text='Главное меню', callback_data='main_menu')
|
||||
|
|
|
@ -9,7 +9,9 @@ boto3==1.35.81
|
|||
botocore==1.35.81
|
||||
certifi==2024.8.30
|
||||
charset-normalizer==3.4.0
|
||||
fastapi==0.115.6
|
||||
frozenlist==1.5.0
|
||||
gunicorn==23.0.0
|
||||
idna==3.10
|
||||
jmespath==1.0.1
|
||||
loguru==0.7.3
|
||||
|
@ -25,4 +27,5 @@ s3transfer==0.10.4
|
|||
six==1.17.0
|
||||
typing_extensions==4.12.2
|
||||
urllib3==2.2.3
|
||||
uvicorn==0.32.1
|
||||
yarl==1.18.3
|
||||
|
|
|
@ -27,14 +27,13 @@ services:
|
|||
depends_on:
|
||||
- backend
|
||||
volumes:
|
||||
- ./clicker_bot:/app
|
||||
- ./bot:/app
|
||||
environment:
|
||||
PROD: 1
|
||||
env_file:
|
||||
- .env/prod/bot
|
||||
- .env/prod/web
|
||||
command:
|
||||
- /gunicorn.sh
|
||||
command: /gunicorn.sh
|
||||
restart: on-failure
|
||||
#
|
||||
# memcached:
|
||||
|
|
|
@ -42,32 +42,32 @@ http {
|
|||
access_log /var/log/nginx/access.log upstreamlog;
|
||||
error_log /var/log/nginx/error.log;
|
||||
listen 80;
|
||||
; listen 443 ssl http2;
|
||||
# listen 443 ssl http2;
|
||||
charset utf-8;
|
||||
; server_name kyc_clicker.ru www.kyc_clicker.ru;
|
||||
# server_name kyc_clicker.ru www.kyc_clicker.ru;
|
||||
|
||||
root /dist/;
|
||||
index index.html;
|
||||
|
||||
; ssl_certificate /etc/letsencrypt/live/kyc_clicker.ru/fullchain.pem;
|
||||
; ssl_certificate_key /etc/letsencrypt/live/kyc_clicker.ru/privkey.pem;
|
||||
# ssl_certificate /etc/letsencrypt/live/kyc_clicker.ru/fullchain.pem;
|
||||
# ssl_certificate_key /etc/letsencrypt/live/kyc_clicker.ru/privkey.pem;
|
||||
|
||||
; include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
# include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
# ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
; if ($server_port = 80) {
|
||||
; set $https_redirect 1;
|
||||
; }
|
||||
; if ($host ~ '^www\.') {
|
||||
; set $https_redirect 1;
|
||||
; }
|
||||
; if ($https_redirect = 1) {
|
||||
; return 301 https://crowngame.ru$request_uri;
|
||||
; }
|
||||
# if ($server_port = 80) {
|
||||
# set $https_redirect 1;
|
||||
# }
|
||||
# if ($host ~ '^www\.') {
|
||||
# set $https_redirect 1;
|
||||
# }
|
||||
# if ($https_redirect = 1) {
|
||||
# return 301 https://crowngame.ru$request_uri;
|
||||
# }
|
||||
|
||||
; location /.well-known/acme-challenge/ {
|
||||
; root /var/www/certbot;
|
||||
; }
|
||||
# location /.well-known/acme-challenge/ {
|
||||
# root /var/www/certbot;
|
||||
# }
|
||||
|
||||
# frontend
|
||||
location / {
|
||||
|
|
Loading…
Reference in New Issue
Block a user