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