From 71f7c4be26f8f6a9bcb93dc1ed79b4d0583287cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D1=8F=20=D0=92=D0=B0=D0=BA=D1=83=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Sat, 21 Dec 2024 11:53:35 +0300 Subject: [PATCH] Added some little fix --- backend/users/celery/mailing_list.py | 4 +++- bot/back_send.py | 29 ++++++++++++++-------------- docker-compose-prod.yml | 5 +---- nginx/nginx.conf | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/backend/users/celery/mailing_list.py b/backend/users/celery/mailing_list.py index eab0ef9..cab8a1e 100644 --- a/backend/users/celery/mailing_list.py +++ b/backend/users/celery/mailing_list.py @@ -19,6 +19,8 @@ def handle_mailing_list(mailing_list_id): ) no_errors = True for mailing_list_receiver_info in mailing_list_receiver_infos: + if mailing_list_receiver_info.sent: + continue user = mailing_list_receiver_info.user body = { 'tg_id': user.tg_id, @@ -44,7 +46,7 @@ def handle_mailing_list(mailing_list_id): @app.task def check_mailing_lists(): - for mailing_list in MailingList.objects.filter(time__lte=timezone.now() + timedelta(hours=1), status=MailingListStatus.WAITING): + for mailing_list in MailingList.objects.filter(time__lte=timezone.now() + timedelta(hours=1), status__in=[MailingListStatus.WAITING, MailingListStatus.PARTLY_FINISHED]): mailing_list.status = MailingListStatus.QUEUED mailing_list.save(update_fields=('status',)) handle_mailing_list.apply_async( diff --git a/bot/back_send.py b/bot/back_send.py index 6dc385a..9e987cf 100644 --- a/bot/back_send.py +++ b/bot/back_send.py @@ -36,21 +36,22 @@ send_message_router = APIRouter( @send_message_router.post('/dispatch/') async def handle_dispatch(data: DispatchSchema, background_tasks: BackgroundTasks): try: - media = io.BytesIO(requests.get(data.attachment_path).content) - media.seek(0) - attachment = types.InputFile(media) - keyboard = InlineKeyboardMarkup() - if data.button_name and data.button_url: - button1 = InlineKeyboardButton(f'{data.button_name}', url=f"{data.button_url}") - keyboard.add(button1) - if data.web_app_button_name: - button2 = InlineKeyboardButton(f'{data.web_app_button_name}', web_app=WebAppInfo(url=f"{url}")) - keyboard.add(button2) + await bot.send_message(data.tg_id, data.text) + # media = io.BytesIO(requests.get(data.attachment_path).content) + # media.seek(0) + # attachment = types.InputFile(media) + # keyboard = InlineKeyboardMarkup() + # if data.button_name and data.button_url: + # button1 = InlineKeyboardButton(f'{data.button_name}', url=f"{data.button_url}") + # keyboard.add(button1) + # if data.web_app_button_name: + # button2 = InlineKeyboardButton(f'{data.web_app_button_name}', web_app=WebAppInfo(url=f"{url}")) + # keyboard.add(button2) - if not data.button_name and not data.web_app_button_name: - await bot.send_photo(data.tg_id, attachment, caption=data.text, parse_mode=types.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove()) - else: - await bot.send_photo(data.tg_id, attachment, caption=data.text, reply_markup=keyboard, parse_mode=types.ParseMode.MARKDOWN) + # if not data.button_name and not data.web_app_button_name: + # await bot.send_photo(data.tg_id, attachment, caption=data.text, parse_mode=types.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove()) + # else: + # await bot.send_photo(data.tg_id, attachment, caption=data.text, reply_markup=keyboard, parse_mode=types.ParseMode.MARKDOWN) except Exception as e: raise HTTPException(status_code=500, detail=str(e)) return {'ok': True} diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index af4ed99..8702e85 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -31,16 +31,12 @@ services: backend: &started-dependency condition: service_started batcher: *started-dependency - memcached: *started-dependency env_file: - .env/prod/bot - .env/prod/web command: /app/scripts/gunicorn.sh restart: on-failure - memcached: - image: memcached:latest - postgres: &pg-conf image: postgres:17-alpine volumes: @@ -65,6 +61,7 @@ services: bot: *started-dependency volumes: - backend_static:/static/ + - backend_media:/media/ restart: unless-stopped celery: diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 341b5af..46d16ff 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -87,7 +87,7 @@ http { } # backend static - location ~ ^/(static)/(.*)$ { + location ~ ^/(static|media)/(.*)$ { alias /$1/$2; }