refactor: remove enqueueUpload from ITelegramService and BotPool
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) <noreply@anthropic.com>
This commit is contained in:
@@ -50,15 +50,4 @@ export interface ITelegramService {
|
|||||||
* @returns Metadata including size, MIME type, download path, and bot token.
|
* @returns Metadata including size, MIME type, download path, and bot token.
|
||||||
*/
|
*/
|
||||||
getFileInfo(telegramFileId: string): Promise<TelegramFileInfo>;
|
getFileInfo(telegramFileId: string): Promise<TelegramFileInfo>;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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<T>(task: () => Promise<T>): Promise<T>;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
sendMethodMap,
|
sendMethodMap,
|
||||||
type TelegramMessageResult,
|
type TelegramMessageResult,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { enqueueUpload } from './upload-queue';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sleep for a given number of milliseconds.
|
* 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.
|
* Forward a file chunk to the configured Telegram storage chat.
|
||||||
*
|
*
|
||||||
* The upload is queued (via {@link enqueueUpload}) and executed with
|
* The upload is executed with automatic bot rotation on rate-limit errors.
|
||||||
* automatic bot rotation on rate-limit errors.
|
|
||||||
*
|
*
|
||||||
* @param fileChunk - The file data (ReadStream, Buffer, or file path).
|
* @param fileChunk - The file data (ReadStream, Buffer, or file path).
|
||||||
* @param fileName - The original file name.
|
* @param fileName - The original file name.
|
||||||
@@ -198,16 +196,14 @@ export class BotPool implements ITelegramService {
|
|||||||
while (attempt <= MAX_TRANSIENT_RETRIES) {
|
while (attempt <= MAX_TRANSIENT_RETRIES) {
|
||||||
attempt++;
|
attempt++;
|
||||||
try {
|
try {
|
||||||
const result = await this.enqueueUpload<TelegramMessageResult>(async () => {
|
|
||||||
const filePayload = { source: fileChunk, filename: fileName };
|
const filePayload = { source: fileChunk, filename: fileName };
|
||||||
const sendMethodName = sendMethodMap[fileType] || 'sendDocument';
|
const sendMethodName = sendMethodMap[fileType] || 'sendDocument';
|
||||||
const payload = buildSendPayload(fileType, fileName);
|
const payload = buildSendPayload(fileType, fileName);
|
||||||
|
|
||||||
return this.executeWithBotRetry<TelegramMessageResult>((activeBot) => {
|
const result = await this.executeWithBotRetry<TelegramMessageResult>((activeBot) => {
|
||||||
const telegram = activeBot.telegram as unknown as Record<string, SendMethod>;
|
const telegram = activeBot.telegram as unknown as Record<string, SendMethod>;
|
||||||
return telegram[sendMethodName](config.storageChatId, filePayload, payload);
|
return telegram[sendMethodName](config.storageChatId, filePayload, payload);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const uploadedFile = extractUploadedFile(result, fileType);
|
const uploadedFile = extractUploadedFile(result, fileType);
|
||||||
logger.info('File forwarded to storage', { fileName, message: result.message_id });
|
logger.info('File forwarded to storage', { fileName, message: result.message_id });
|
||||||
@@ -302,19 +298,6 @@ export class BotPool implements ITelegramService {
|
|||||||
});
|
});
|
||||||
throw lastError;
|
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<T>(task: () => Promise<T>): Promise<T> {
|
|
||||||
return enqueueUpload(task);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user