baha-99 commited on
Commit
6bd2c3d
·
1 Parent(s): 766a55c

fix: Excel file error fix

Browse files
Files changed (1) hide show
  1. bot_telegram.py +40 -0
bot_telegram.py CHANGED
@@ -7,6 +7,7 @@ import aiohttp
7
  import io
8
  import asyncio
9
  from concurrent.futures import ThreadPoolExecutor
 
10
 
11
  # Configure logging
12
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
@@ -264,9 +265,48 @@ class TelegramBot:
264
  except Exception as e:
265
  return None, str(e)
266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  def setup_handlers(self):
268
  """Set up Telegram command and message handlers."""
269
  self.app.add_handler(CommandHandler("start", self.start_command))
 
270
  self.app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_message))
271
  self.app.add_handler(MessageHandler(filters.Document.FileExtension("xlsx") | filters.Document.FileExtension("xls"), self.handle_excel))
272
 
 
7
  import io
8
  import asyncio
9
  from concurrent.futures import ThreadPoolExecutor
10
+ import time
11
 
12
  # Configure logging
13
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
 
265
  except Exception as e:
266
  return None, str(e)
267
 
268
+ async def test_concurrent(self, update: Update, context: CallbackContext):
269
+ """Test concurrent processing"""
270
+ await update.message.reply_text("Sending 5 requests simultaneously...")
271
+
272
+ tasks = []
273
+ for i in range(5):
274
+ msg = f"Test question {i+1}"
275
+ tasks.append(self.chat_with_ai(update, context))
276
+
277
+ await asyncio.gather(*tasks)
278
+
279
+ async def load_test_command(self, update: Update, context: CallbackContext):
280
+ """Command to test concurrent processing"""
281
+ if not context.args or not context.args[0].isdigit():
282
+ await update.message.reply_text("Usage: /loadtest <number_of_requests>")
283
+ return
284
+
285
+ num_requests = min(int(context.args[0]), 20) # Limit to 20 for safety
286
+ await update.message.reply_text(f"Starting load test with {num_requests} concurrent requests...")
287
+
288
+ start_time = time.time()
289
+ tasks = []
290
+ for i in range(num_requests):
291
+ tasks.append(self.chat_with_ai(
292
+ update,
293
+ context,
294
+ f"Test question {i+1}"
295
+ ))
296
+
297
+ await asyncio.gather(*tasks)
298
+ duration = time.time() - start_time
299
+
300
+ await update.message.reply_text(
301
+ f"Load test completed!\n"
302
+ f"Processed {num_requests} requests in {duration:.2f} seconds\n"
303
+ f"Average time per request: {(duration/num_requests):.2f} seconds"
304
+ )
305
+
306
  def setup_handlers(self):
307
  """Set up Telegram command and message handlers."""
308
  self.app.add_handler(CommandHandler("start", self.start_command))
309
+ self.app.add_handler(CommandHandler("loadtest", self.load_test_command))
310
  self.app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_message))
311
  self.app.add_handler(MessageHandler(filters.Document.FileExtension("xlsx") | filters.Document.FileExtension("xls"), self.handle_excel))
312