更新下载图像方法以返回 Uint8Array,调整下载任务的重试延迟和并发设置,优化提示词工作者的日志输出

This commit is contained in:
2026-01-10 16:51:18 +08:00
parent 813c0709c8
commit 62885005e0
3 changed files with 8 additions and 8 deletions

View File

@@ -80,7 +80,7 @@ export class JimengService {
} }
} }
async downloadImage(url: string): Promise<Buffer> { async downloadImage(url: string): Promise<Uint8Array> {
const controller = new AbortController(); const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), this.timeout); const timeoutId = setTimeout(() => controller.abort(), this.timeout);
@@ -96,7 +96,7 @@ export class JimengService {
} }
const arrayBuffer = await response.arrayBuffer(); const arrayBuffer = await response.arrayBuffer();
return Buffer.from(arrayBuffer); return new Uint8Array(arrayBuffer);
} catch (error: any) { } catch (error: any) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
if (error.name === 'AbortError') { if (error.name === 'AbortError') {

View File

@@ -95,7 +95,7 @@ export async function addImageDownloadJob(
attempts: DOWNLOAD_MAX_RETRIES, attempts: DOWNLOAD_MAX_RETRIES,
backoff: { backoff: {
type: 'exponential', type: 'exponential',
delay: 2000, // 初始 2 delay: 200, // 初始 200 毫
}, },
removeOnComplete: 100, removeOnComplete: 100,
removeOnFail: 100, removeOnFail: 100,
@@ -147,7 +147,7 @@ export async function runImageDownloadWorker(): Promise<void> {
}, },
{ {
connection, connection,
concurrency: 3, concurrency: 1, // 避免更新冲突
lockDuration: 60000 * 5, // 锁持续时间 5分钟 lockDuration: 60000 * 5, // 锁持续时间 5分钟
stalledInterval: 30000, // 每30秒检查一次 stalled stalledInterval: 30000, // 每30秒检查一次 stalled
} as any } as any
@@ -162,7 +162,7 @@ export async function runImageDownloadWorker(): Promise<void> {
notify.notify(`[ImageDownload] \nJob failed: ${job?.id}, error: ${err.message}\n Job data: ${JSON.stringify(job?.data)}`); notify.notify(`[ImageDownload] \nJob failed: ${job?.id}, error: ${err.message}\n Job data: ${JSON.stringify(job?.data)}`);
}); });
console.log('[ImageDownload] Worker started'); console.log('[ImageDownload] Worker 开始运行');
} }
/** /**
@@ -226,7 +226,7 @@ export async function runImageGenerateWorker(): Promise<void> {
} }
}); });
console.log('[ImageGenerate] Worker started'); console.log('[ImageGenerate] Worker 开始运行');
} }
export { updateItemStatus }; export { updateItemStatus };

View File

@@ -116,6 +116,6 @@ export const runPerfectSentencePromptWorker = () => {
notify.notify(`[Sentence] 提示词优化工作者在条目 ${job.data.itemId} 达到最大重试次数后停止`); notify.notify(`[Sentence] 提示词优化工作者在条目 ${job.data.itemId} 达到最大重试次数后停止`);
} }
}); });
console.log('[Sentence] Worker 开始运行');
return worker; return worker;
}; };