feat: Add transcription worker and state management

Introduce an `AppState` struct to hold shared application state,
including configuration and the transcription sender.
Modify `create_router` and `create_router_with_state` to use `AppState`.
Update `main.rs` to initialize the transcription worker and pass the
`AppState` to the router.
Implement the transcription worker logic in
`server/src/transcribe/worker.rs`, handling job queues, FFmpeg remuxing,
and Whisper transcription.
Update `server/src/auth.rs` to use `Arc<Config>` from the shared state.
Modify `server/src/routes/upload.rs` to enqueue transcription jobs and
handle potential errors.
Add `TranscribeJob` and channel types in `server/src/transcribe/mod.rs`.
This commit is contained in:
2026-04-13 16:45:24 +02:00
parent 84f8df2bf4
commit bcae4e5466
7 changed files with 158 additions and 19 deletions
+19 -1
View File
@@ -9,6 +9,8 @@ use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;
use doctate_server::config::Config;
use doctate_server::transcribe;
use doctate_server::AppState;
#[tokio::main]
async fn main() {
@@ -37,10 +39,26 @@ async fn main() {
)
.init();
// Transcription pipeline: shared HTTP client + worker task.
let (transcribe_tx, transcribe_rx) = transcribe::channel();
let http_client = reqwest::Client::builder()
.build()
.expect("reqwest client build failed");
tokio::spawn(transcribe::worker::run(
transcribe_rx,
config.clone(),
http_client,
));
let state = AppState {
config: config.clone(),
transcribe_tx,
};
let addr = format!("0.0.0.0:{}", config.server_port);
info!(port = config.server_port, "Server starting");
let app = doctate_server::create_router(config)
let app = doctate_server::create_router_with_state(state)
.layer(TraceLayer::new_for_http())
.layer(RequestBodyLimitLayer::new(50 * 1024 * 1024)); // 50 MB