From d7d6ae0f0db38c26c3b23a401e73140c37b4a3b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 29 Jul 2026 13:14:26 +0700 Subject: [PATCH] refactor: remove enqueueUpload from ITelegramService and BotPool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per-bot queue replaces global upload queue — BotPool handles queueing internally. - Remove enqueueUpload method signature from ITelegramService interface - Remove enqueueUpload method from BotPool class - Remove import of enqueueUpload from upload-queue module - Refactor forwardToStorage to call executeWithBotRetry directly instead of wrapping via enqueueUpload - Fix trailing blank lines flagged by Biome formatter Co-Authored-By: Claude Opus 5 (1M context) --- src/domain/ports/telegram-service.ts | 11 --------- src/infrastructure/telegram/bot-pool.ts | 31 ++++++------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/domain/ports/telegram-service.ts b/src/domain/ports/telegram-service.ts index 4f16e99..8372a64 100644 --- a/src/domain/ports/telegram-service.ts +++ b/src/domain/ports/telegram-service.ts @@ -50,15 +50,4 @@ export interface ITelegramService { * @returns Metadata including size, MIME type, download path, and bot token. */ getFileInfo(telegramFileId: string): Promise; - - /** - * Enqueue a task for sequential upload execution. - * - * Ensures only one Telegram upload runs at a time to avoid - * rate limits and resource contention. - * - * @param task - An async function performing the upload. - * @returns The result of the task. - */ - enqueueUpload(task: () => Promise): Promise; } diff --git a/src/infrastructure/telegram/bot-pool.ts b/src/infrastructure/telegram/bot-pool.ts index dd20098..405e695 100644 --- a/src/infrastructure/telegram/bot-pool.ts +++ b/src/infrastructure/telegram/bot-pool.ts @@ -13,7 +13,6 @@ import { sendMethodMap, type TelegramMessageResult, } from './types'; -import { enqueueUpload } from './upload-queue'; /** * Sleep for a given number of milliseconds. @@ -179,8 +178,7 @@ export class BotPool implements ITelegramService { /** * Forward a file chunk to the configured Telegram storage chat. * - * The upload is queued (via {@link enqueueUpload}) and executed with - * automatic bot rotation on rate-limit errors. + * The upload is executed with automatic bot rotation on rate-limit errors. * * @param fileChunk - The file data (ReadStream, Buffer, or file path). * @param fileName - The original file name. @@ -198,15 +196,13 @@ export class BotPool implements ITelegramService { while (attempt <= MAX_TRANSIENT_RETRIES) { attempt++; try { - const result = await this.enqueueUpload(async () => { - const filePayload = { source: fileChunk, filename: fileName }; - const sendMethodName = sendMethodMap[fileType] || 'sendDocument'; - const payload = buildSendPayload(fileType, fileName); + const filePayload = { source: fileChunk, filename: fileName }; + const sendMethodName = sendMethodMap[fileType] || 'sendDocument'; + const payload = buildSendPayload(fileType, fileName); - return this.executeWithBotRetry((activeBot) => { - const telegram = activeBot.telegram as unknown as Record; - return telegram[sendMethodName](config.storageChatId, filePayload, payload); - }); + const result = await this.executeWithBotRetry((activeBot) => { + const telegram = activeBot.telegram as unknown as Record; + return telegram[sendMethodName](config.storageChatId, filePayload, payload); }); const uploadedFile = extractUploadedFile(result, fileType); @@ -302,19 +298,6 @@ export class BotPool implements ITelegramService { }); throw lastError; } - - /** - * Enqueue a task for sequential upload execution. - * - * Delegates to the shared upload queue to ensure only a limited number - * of Telegram uploads run concurrently. - * - * @param task - An async function performing the upload. - * @returns The result of the task. - */ - enqueueUpload(task: () => Promise): Promise { - return enqueueUpload(task); - } } /**