Изменение на 23.02.2026 22:06
This commit is contained in:
@@ -9,6 +9,7 @@ package usecase
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -172,10 +173,15 @@ func (uc *ProcessAudioBooksUseCase) processOneBook(ctx context.Context, folderPa
|
||||
}
|
||||
info, err := uc.extractor.Extract(ctx, folderPath)
|
||||
if err != nil {
|
||||
reason := fmt.Sprintf("извлечение метаданных: %v", err)
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogError(folderName, fmt.Errorf("извлечение метаданных: %w", err))
|
||||
uc.logger.LogError(folderName, fmt.Errorf("%s", reason))
|
||||
}
|
||||
return domain.ProcessResult{Err: fmt.Errorf("[%s] извлечение метаданных: %w", folderPath, err)}
|
||||
_ = uc.moveToErrorFolder(folderPath, resultRoot, reason)
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogInfo(fmt.Sprintf("[%s] Папка перенесена в ERROR/", folderName))
|
||||
}
|
||||
return domain.ProcessResult{Err: fmt.Errorf("[%s] %s", folderName, reason)}
|
||||
}
|
||||
|
||||
enriched := &domain.EnrichedBookInfo{
|
||||
@@ -260,6 +266,18 @@ func (uc *ProcessAudioBooksUseCase) processOneBook(ctx context.Context, folderPa
|
||||
select {
|
||||
case <-time.After(uc.cfg.SearchRetryDelay):
|
||||
case <-ctx.Done():
|
||||
// Таймаут/отмена сессии — если не явный выход пользователя, переносим в ERROR
|
||||
if !errors.Is(ctx.Err(), context.Canceled) {
|
||||
reason := fmt.Sprintf("прерывание на попытке %d/%d: %v", attempt, uc.cfg.SearchRetries, ctx.Err())
|
||||
enriched.ErrorMessage = reason
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogError(folderName, fmt.Errorf("%s", reason))
|
||||
}
|
||||
_ = uc.moveToErrorFolder(folderPath, resultRoot, reason)
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogInfo(fmt.Sprintf("[%s] Папка перенесена в ERROR/", folderName))
|
||||
}
|
||||
}
|
||||
return domain.ProcessResult{Book: enriched, Err: ctx.Err()}
|
||||
}
|
||||
if uc.logger != nil {
|
||||
@@ -273,6 +291,17 @@ func (uc *ProcessAudioBooksUseCase) processOneBook(ctx context.Context, folderPa
|
||||
break
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
if !errors.Is(ctx.Err(), context.Canceled) {
|
||||
reason := fmt.Sprintf("прерывание при поиске (попытка %d/%d): %v", attempt, uc.cfg.SearchRetries, ctx.Err())
|
||||
enriched.ErrorMessage = reason
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogError(folderName, fmt.Errorf("%s", reason))
|
||||
}
|
||||
_ = uc.moveToErrorFolder(folderPath, resultRoot, reason)
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogInfo(fmt.Sprintf("[%s] Папка перенесена в ERROR/", folderName))
|
||||
}
|
||||
}
|
||||
return domain.ProcessResult{Book: enriched, Err: ctx.Err()}
|
||||
}
|
||||
lastSearchErrMsg = errMsg
|
||||
@@ -314,12 +343,17 @@ func (uc *ProcessAudioBooksUseCase) processOneBook(ctx context.Context, folderPa
|
||||
}
|
||||
destDir, writeErr := uc.writer.WriteResult(ctx, enriched, resultRoot)
|
||||
if writeErr != nil {
|
||||
reason := fmt.Sprintf("запись результата: %v", writeErr)
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogError(folderName, fmt.Errorf("запись результата: %w", writeErr))
|
||||
uc.logger.LogError(folderName, fmt.Errorf("%s", reason))
|
||||
}
|
||||
_ = uc.moveToErrorFolder(folderPath, resultRoot, reason)
|
||||
if uc.logger != nil {
|
||||
uc.logger.LogInfo(fmt.Sprintf("[%s] Папка перенесена в ERROR/", folderName))
|
||||
}
|
||||
return domain.ProcessResult{
|
||||
Book: enriched,
|
||||
Err: fmt.Errorf("[%s] запись результата: %w", folderPath, writeErr),
|
||||
Err: fmt.Errorf("[%s] %s", folderName, reason),
|
||||
}
|
||||
}
|
||||
enriched.DestFolder = destDir
|
||||
|
||||
Reference in New Issue
Block a user