refactor: Major overhaul with error handling, resilience patterns, and observability

- Add library configuration to support both lib and binary targets
- Implement unified error handling with NCBError throughout the codebase
- Add circuit breaker pattern for external API calls (Voicevox, GCP TTS)
- Introduce comprehensive performance metrics and monitoring
- Add cache persistence with disk storage support
- Implement retry mechanism with exponential backoff
- Add configuration file support (config.toml) with env var fallback
- Enhance logging with structured tracing (debug, warn, error levels)
- Add extensive unit tests for cache, metrics, and circuit breaker
- Update base64 decoding to use modern API
- Improve API error handling for Voicevox and GCP TTS clients

Breaking changes:
- Function signatures now return Result<T, NCBError> instead of panicking
- Cache key structure modified with serialization support
This commit is contained in:
mii443
2025-05-28 01:01:12 +09:00
parent 0bea81aa6e
commit 733646b6b8
19 changed files with 2508 additions and 382 deletions

View File

@ -3,6 +3,14 @@ name = "ncb-tts-r2"
version = "1.11.2"
edition = "2021"
[lib]
name = "ncb_tts_r2"
path = "src/lib.rs"
[[bin]]
name = "ncb-tts-r2"
path = "src/main.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@ -13,10 +21,15 @@ gcp_auth = "0.5.0"
reqwest = { version = "0.12.9", features = ["json"] }
base64 = "0.22.1"
async-trait = "0.1.57"
redis = "0.29.2"
redis = { version = "0.29.2", features = ["aio", "tokio-comp"] }
bb8 = "0.8"
bb8-redis = "0.16"
thiserror = "1.0"
regex = "1"
tracing-subscriber = "0.3.19"
lru = "0.13.0"
once_cell = "1.19"
bincode = "1.3"
tracing = "0.1.41"
opentelemetry_sdk = { version = "0.29.0", features = ["trace"] }
opentelemetry = "0.29.1"
@ -61,3 +74,9 @@ features = [
[dependencies.tokio]
version = "1.0"
features = ["macros", "rt-multi-thread"]
[dev-dependencies]
tokio-test = "0.4"
mockall = "0.12"
tempfile = "3.8"
serial_test = "3.0"