add timeout

This commit is contained in:
Kseninia Mikhaylova 2024-07-18 14:47:14 +03:00
parent 76b7ce67eb
commit 1cf0a60c27
4 changed files with 15 additions and 12 deletions

View File

@ -10,7 +10,7 @@ class TgBotUpdater:
tgbot_class = None tgbot_class = None
my_queue = queue.Queue() my_queue = queue.Queue()
return_queue = queue.Queue() return_values = dict()
import logging import logging

View File

@ -67,7 +67,7 @@ class TgBot:
async for item in queryset: async for item in queryset:
try: try:
text = await TgBot.app.bot.get_file(item.text) text = await TgBot.app.bot.get_file(item.text)
TgBotUpdater.return_queue.put(text.file_path) TgBotUpdater.return_values[item.text] = text.file_path
except Exception as e: except Exception as e:
pass pass

View File

@ -43,13 +43,14 @@ class TmcFieldViewset(viewsets.ModelViewSet):
field = TmcField.objects.filter(id=field_id) field = TmcField.objects.filter(id=field_id)
TgBotUpdater.my_queue.put({"name": "admin_get_image", "queryset": field}) TgBotUpdater.my_queue.put({"name": "admin_get_image", "queryset": field})
response = [] response = []
timer = 3 timer = 30
while timer > 0: while timer > 0:
sleeping = 1 sleeping = 1
timer -= sleeping timer -= sleeping
time.sleep(sleeping) time.sleep(sleeping)
if not TgBotUpdater.return_queue.empty(): if field[0].text in TgBotUpdater.return_values:
response.append(TgBotUpdater.return_queue.get()) response.append(TgBotUpdater.return_values[field[0].text])
del TgBotUpdater.return_values[field[0].text]
break break
return Response(response) return Response(response)
else: else:

View File

@ -16,11 +16,13 @@ const openImage = () => {
isOpen.value = !isOpen.value isOpen.value = !isOpen.value
} }
</script> </script>
<template v-if="file_url"> <template>
<a href="#"> <template v-if="file_url">
<Icon name="i-mdi-image" @click="openImage" /> <a href="#">
</a> <Icon name="i-mdi-image" @click="openImage" />
<UModal v-model="isOpen"> </a>
<img :src="file_url" /> <UModal v-model="isOpen">
</UModal> <img :src="file_url" />
</UModal>
</template>
</template> </template>