Worker: separate containers for e-mail and AI generation
CI / test (push) Successful in 1m9s
CI / build (push) Successful in 4m9s
CI / deploy (push) Skipped

WORKER_TASKS (email, cleanup, analyses; all by default) picks the jobs of a
worker process. In production the worker sends e-mails and cleans up (and
will take the other background jobs), worker-ai writes the analyses and
answers with its quick and slow lanes, sized from the server's .env.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-19 06:51:45 +00:00
co-authored by Claude Opus 5.5
parent bc0227042b
commit da533e8fa9
7 changed files with 81 additions and 2 deletions
+10 -1
View File
@@ -5,6 +5,9 @@
//! * hourly cleanup of expired sessions, tokens, invites and old e-mails
//! * writing the requested text analyses with an LLM (OpenRouter)
//!
//! `WORKER_TASKS` (e.g. `email,cleanup` or `analyses`) picks the jobs of one
//! process, so they can run in separate containers; all of them by default.
//!
//! Configuration: see [`config::Config`]; plus `BIND_ADDR` (default
//! `0.0.0.0:8082`, only `/healthz`), `LOG_FORMAT` and `RUST_LOG`.
//! `worker healthcheck` performs a local health check (for Docker);
@@ -91,7 +94,10 @@ async fn main() -> anyhow::Result<()> {
let (stop_tx, stop) = watch::channel(false);
let mut jobs = tokio::task::JoinSet::new();
let tasks = config.tasks;
tracing::info!(email = tasks.email, cleanup = tasks.cleanup, analyses = tasks.analyses, "worker tasks");
match &config.smtp_url {
_ if !tasks.email => {}
Some(url) => {
let delivery = email::Delivery::new(pool.clone(), email::Mailer::smtp(url)?, &config);
let via = config.smtp_about.clone().unwrap_or_else(|| "SMTP_URL".into());
@@ -101,6 +107,7 @@ async fn main() -> anyhow::Result<()> {
None => tracing::warn!("neither SMTP_URL nor SES credentials are set: e-mails stay in the outbox"),
}
match &config.openrouter_api_key {
_ if !tasks.analyses => {}
Some(key) => {
let llm =
analysis::openrouter::OpenRouter::new(&config.openrouter_base_url, key, config.public_base_url.clone());
@@ -115,7 +122,9 @@ async fn main() -> anyhow::Result<()> {
}
None => tracing::warn!("OPENROUTER_API_KEY is not set: analyses stay pending"),
}
jobs.spawn(cleanup::run(pool.clone(), stop.clone()));
if tasks.cleanup {
jobs.spawn(cleanup::run(pool.clone(), stop.clone()));
}
let app = Router::new().route("/healthz", get(healthz)).with_state(pool);
let listener = tokio::net::TcpListener::bind(addr).await.with_context(|| format!("binding {addr}"))?;