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
my_queue = queue.Queue()
return_queue = queue.Queue()
return_values = dict()
import logging

View File

@ -67,7 +67,7 @@ class TgBot:
async for item in queryset:
try:
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:
pass

View File

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

View File

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