Added some little fix

This commit is contained in:
Даня Вакуленков 2024-12-21 11:53:35 +03:00
parent b0c0fecee9
commit 71f7c4be26
4 changed files with 20 additions and 20 deletions

View File

@ -19,6 +19,8 @@ def handle_mailing_list(mailing_list_id):
) )
no_errors = True no_errors = True
for mailing_list_receiver_info in mailing_list_receiver_infos: for mailing_list_receiver_info in mailing_list_receiver_infos:
if mailing_list_receiver_info.sent:
continue
user = mailing_list_receiver_info.user user = mailing_list_receiver_info.user
body = { body = {
'tg_id': user.tg_id, 'tg_id': user.tg_id,
@ -44,7 +46,7 @@ def handle_mailing_list(mailing_list_id):
@app.task @app.task
def check_mailing_lists(): 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.status = MailingListStatus.QUEUED
mailing_list.save(update_fields=('status',)) mailing_list.save(update_fields=('status',))
handle_mailing_list.apply_async( handle_mailing_list.apply_async(

View File

@ -36,21 +36,22 @@ send_message_router = APIRouter(
@send_message_router.post('/dispatch/') @send_message_router.post('/dispatch/')
async def handle_dispatch(data: DispatchSchema, background_tasks: BackgroundTasks): async def handle_dispatch(data: DispatchSchema, background_tasks: BackgroundTasks):
try: try:
media = io.BytesIO(requests.get(data.attachment_path).content) await bot.send_message(data.tg_id, data.text)
media.seek(0) # media = io.BytesIO(requests.get(data.attachment_path).content)
attachment = types.InputFile(media) # media.seek(0)
keyboard = InlineKeyboardMarkup() # attachment = types.InputFile(media)
if data.button_name and data.button_url: # keyboard = InlineKeyboardMarkup()
button1 = InlineKeyboardButton(f'{data.button_name}', url=f"{data.button_url}") # if data.button_name and data.button_url:
keyboard.add(button1) # button1 = InlineKeyboardButton(f'{data.button_name}', url=f"{data.button_url}")
if data.web_app_button_name: # keyboard.add(button1)
button2 = InlineKeyboardButton(f'{data.web_app_button_name}', web_app=WebAppInfo(url=f"{url}")) # if data.web_app_button_name:
keyboard.add(button2) # 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: # 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()) # await bot.send_photo(data.tg_id, attachment, caption=data.text, parse_mode=types.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove())
else: # else:
await bot.send_photo(data.tg_id, attachment, caption=data.text, reply_markup=keyboard, parse_mode=types.ParseMode.MARKDOWN) # await bot.send_photo(data.tg_id, attachment, caption=data.text, reply_markup=keyboard, parse_mode=types.ParseMode.MARKDOWN)
except Exception as e: except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) raise HTTPException(status_code=500, detail=str(e))
return {'ok': True} return {'ok': True}

View File

@ -31,16 +31,12 @@ services:
backend: &started-dependency backend: &started-dependency
condition: service_started condition: service_started
batcher: *started-dependency batcher: *started-dependency
memcached: *started-dependency
env_file: env_file:
- .env/prod/bot - .env/prod/bot
- .env/prod/web - .env/prod/web
command: /app/scripts/gunicorn.sh command: /app/scripts/gunicorn.sh
restart: on-failure restart: on-failure
memcached:
image: memcached:latest
postgres: &pg-conf postgres: &pg-conf
image: postgres:17-alpine image: postgres:17-alpine
volumes: volumes:
@ -65,6 +61,7 @@ services:
bot: *started-dependency bot: *started-dependency
volumes: volumes:
- backend_static:/static/ - backend_static:/static/
- backend_media:/media/
restart: unless-stopped restart: unless-stopped
celery: celery:

View File

@ -87,7 +87,7 @@ http {
} }
# backend static # backend static
location ~ ^/(static)/(.*)$ { location ~ ^/(static|media)/(.*)$ {
alias /$1/$2; alias /$1/$2;
} }