strip session-added comments
This commit is contained in:
@@ -58,8 +58,6 @@ pub async fn build_database_adapters(
|
||||
assemble(w, instance)
|
||||
}
|
||||
|
||||
/// Like [`build_database_adapters`], on a pool the caller already connected
|
||||
/// (migrations still run). Lets tests drive the real wiring on an in-memory pool.
|
||||
pub async fn build_database_adapters_on(
|
||||
pool: sqlx::SqlitePool,
|
||||
instance: &domain::value_objects::InstanceIdentity,
|
||||
|
||||
@@ -27,8 +27,6 @@ impl EventBusBackend {
|
||||
}
|
||||
}
|
||||
|
||||
/// The server's publisher is always the outbox writer: it never talks to the
|
||||
/// bus, whatever `EVENT_BUS_BACKEND` says. The worker owns delivery.
|
||||
pub async fn create_publisher(
|
||||
db_pool: &sqlx::SqlitePool,
|
||||
config: &config::AppConfig,
|
||||
@@ -37,18 +35,12 @@ pub async fn create_publisher(
|
||||
sqlite::SqliteEventQueue::create_publisher(db_pool.clone(), &config.events).await
|
||||
}
|
||||
|
||||
/// What the worker gets from the bus: a publisher for its own events, the
|
||||
/// consumer its handlers read, and, when the bus is not the outbox, the relay
|
||||
/// that moves outbox rows onto it.
|
||||
struct Wiring {
|
||||
publisher: Arc<dyn EventPublisher>,
|
||||
consumer: Arc<dyn EventConsumer>,
|
||||
relay: Option<OutboxRelay>,
|
||||
}
|
||||
|
||||
/// The worker always writes to the outbox. With an external bus
|
||||
/// (`bus = Some((consumer, sink))`) handlers read from the bus and the relay
|
||||
/// drains the outbox into it; without one, handlers drain the outbox directly.
|
||||
fn compose(
|
||||
(publisher, outbox): (Arc<dyn EventPublisher>, Arc<dyn EventConsumer>),
|
||||
bus: Option<(Arc<dyn EventConsumer>, Arc<dyn EventRelaySink>)>,
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
//! Social and federation wiring for the server and worker.
|
||||
//!
|
||||
//! Federation off still wires real local social behaviour (`LocalSocialService`):
|
||||
//! the follow graph and block queries must never silently report empty.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::ports::{
|
||||
@@ -123,9 +118,6 @@ pub async fn wire_server_social(
|
||||
})
|
||||
}
|
||||
|
||||
/// The worker's federation event handlers (the ActivityPub delivery handler and
|
||||
/// the follow-accepted outbox backfill) and the notifier that tells followers
|
||||
/// an account was deleted.
|
||||
#[cfg(feature = "federation")]
|
||||
pub async fn wire_worker_handlers(
|
||||
db: &DatabaseOutput,
|
||||
|
||||
@@ -62,11 +62,6 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The handler has no state of its own: idempotency lives behind the port
|
||||
/// (remote imports are keyed upserts; backfill Creates use the deterministic
|
||||
/// k-ap id `activities/create/{uuidv5(object id)}`, see activitypub
|
||||
/// `tests/activity_ids.rs`). What this proves is that a redelivery replays
|
||||
/// exactly the same port calls, with no accumulated or derived state.
|
||||
#[derive(Default)]
|
||||
struct CallLog(Mutex<Vec<String>>);
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
//! The composition root: the only crate that names concrete adapters.
|
||||
//!
|
||||
//! `server` and `worker` are thin binaries over [`build_server`] and
|
||||
//! [`build_worker`]; everything between configuration and a running service is
|
||||
//! assembled here (ADR-0005, ADR-0013).
|
||||
|
||||
mod build;
|
||||
mod database;
|
||||
mod event_bus;
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
//! Moves outbox rows onto the message bus. The worker runs it when the bus is
|
||||
//! not the outbox itself (`EVENT_BUS_BACKEND=nats`).
|
||||
//!
|
||||
//! Rows are claimed by the SQLite queue's own atomic claim, so a row is
|
||||
//! relayed by one claimant at a time, and failures take the queue's backoff
|
||||
//! and dead-letter path. A row is marked done only after the sink reports the
|
||||
//! bus accepted it.
|
||||
//!
|
||||
//! A sink (transport) failure is the bus's fault, not the row's: the row is
|
||||
//! deferred without spending an attempt, and the relay pauses with a growing
|
||||
//! backoff instead of churning through the rest of the outbox. Attempts, and
|
||||
//! so dead-lettering, are only ever spent by consumers on handler failures.
|
||||
//!
|
||||
//! Delivery is at-least-once. A crash between publish and mark-done leaves the
|
||||
//! row `processing`; when its claim lease lapses it is claimed and relayed
|
||||
//! again. The bus drops that repeat while it is inside the broker's dedup
|
||||
//! window (same `Nats-Msg-Id`); beyond the window, or in core mode, the
|
||||
//! consumer ledger makes the handlers skip it.
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use domain::{
|
||||
@@ -41,16 +22,11 @@ impl OutboxRelay {
|
||||
}
|
||||
}
|
||||
|
||||
/// Overrides the pause/defer schedule, keyed by consecutive sink failures.
|
||||
pub fn with_backoff(mut self, backoff: fn(u32) -> Duration) -> Self {
|
||||
self.backoff = backoff;
|
||||
self
|
||||
}
|
||||
|
||||
/// Runs until `shutdown` fires or the source ends. A shutdown never
|
||||
/// interrupts a row mid-relay: it is acked or nacked before this returns.
|
||||
/// Rows the claim already took but the relay had not started stay
|
||||
/// `processing` and come back when their lease lapses.
|
||||
pub async fn run(self, mut shutdown: watch::Receiver<bool>) {
|
||||
let mut rows = self.source.consume();
|
||||
let mut sink_failures: u32 = 0;
|
||||
@@ -80,7 +56,6 @@ impl OutboxRelay {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The queue already dead-lettered it and logged the row id.
|
||||
Some(Err(e)) => tracing::error!("outbox relay: skipped undecodable row: {e}"),
|
||||
None => {
|
||||
tracing::error!("outbox relay: source closed");
|
||||
@@ -92,7 +67,6 @@ impl OutboxRelay {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns how long the relay should pause when the sink failed.
|
||||
async fn relay_envelope(
|
||||
envelope: EventEnvelope,
|
||||
sink: &dyn EventRelaySink,
|
||||
|
||||
@@ -19,7 +19,6 @@ pub struct ServerApp {
|
||||
pub addr: SocketAddr,
|
||||
}
|
||||
|
||||
/// Wires the whole HTTP application from configuration.
|
||||
pub async fn build_server(config: &config::AppConfig) -> anyhow::Result<ServerApp> {
|
||||
database::warn_if_database_backend_set();
|
||||
let instance = InstanceIdentity::new(config.server.base_url.clone());
|
||||
@@ -28,7 +27,6 @@ pub async fn build_server(config: &config::AppConfig) -> anyhow::Result<ServerAp
|
||||
.await
|
||||
.context("Failed to wire dependencies")?;
|
||||
|
||||
// Resolved like `TcpListener::bind(&str)` would, so a hostname HOST keeps working.
|
||||
let bind = format!("{}:{}", config.server.host, config.server.port);
|
||||
let addr = tokio::net::lookup_host(&bind)
|
||||
.await
|
||||
@@ -38,8 +36,6 @@ pub async fn build_server(config: &config::AppConfig) -> anyhow::Result<ServerAp
|
||||
Ok(ServerApp { router, addr })
|
||||
}
|
||||
|
||||
/// Builds the same router as [`build_server`] on a caller-provided pool.
|
||||
/// Migrations run on it exactly as they do for the normal path.
|
||||
pub async fn build_server_on(
|
||||
config: &config::AppConfig,
|
||||
pool: sqlx::SqlitePool,
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
//! Process-wide rustls crypto provider.
|
||||
//!
|
||||
//! Every HTTPS client in the graph (reqwest, object_store, async-nats,
|
||||
//! k-ap) is built without a bundled provider so the binaries link `ring`
|
||||
//! only. rustls therefore needs one installed before the first client is
|
||||
//! built, or client construction panics.
|
||||
|
||||
use std::sync::Once;
|
||||
|
||||
/// Installs `ring` as the process default. Idempotent; a provider installed
|
||||
/// earlier by someone else is left in place.
|
||||
pub fn install_crypto_provider() {
|
||||
static INSTALL: Once = Once::new();
|
||||
INSTALL.call_once(|| {
|
||||
@@ -20,8 +11,6 @@ pub fn install_crypto_provider() {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Only test in this crate's lib test binary, so nothing else in this
|
||||
/// process installs a provider before `install_crypto_provider` runs.
|
||||
#[test]
|
||||
fn https_client_builds_after_install() {
|
||||
install_crypto_provider();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
/// Installs the global subscriber. `RUST_LOG` overrides `default_directives`.
|
||||
pub fn init_tracing(default_directives: &str) {
|
||||
tracing_subscriber::registry()
|
||||
.with(log_filter(default_directives))
|
||||
|
||||
@@ -13,23 +13,14 @@ use tokio::sync::watch;
|
||||
|
||||
pub struct WorkerApp {
|
||||
service: WorkerService,
|
||||
/// Present when the bus is external: drains the outbox into it.
|
||||
relay: Option<OutboxRelay>,
|
||||
}
|
||||
|
||||
impl WorkerApp {
|
||||
/// Names of the registered event handlers, in registration order.
|
||||
pub fn handler_names(&self) -> Vec<&'static str> {
|
||||
self.service.handler_names()
|
||||
}
|
||||
|
||||
/// Runs the handlers and, when there is one, the outbox relay, until
|
||||
/// `shutdown` fires. Both stop together and finish their in-flight work.
|
||||
///
|
||||
/// If the relay stops or panics on its own, the worker stops too and
|
||||
/// returns an error so the process exits non-zero and the supervisor
|
||||
/// restarts it: a worker that keeps handling events but no longer
|
||||
/// delivers the outbox would fail silently.
|
||||
pub async fn run(self, mut shutdown: watch::Receiver<bool>) -> anyhow::Result<()> {
|
||||
let (stop_tx, stop_rx) = watch::channel(false);
|
||||
let mut relay = self.relay.map(|r| tokio::spawn(r.run(stop_rx.clone())));
|
||||
@@ -74,8 +65,6 @@ impl WorkerApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wires the background worker: event handlers, periodic jobs (already
|
||||
/// spawned) and the consumer. Run it with `service.run(shutdown)`.
|
||||
pub async fn build_worker(config: &config::AppConfig) -> anyhow::Result<WorkerApp> {
|
||||
database::warn_if_database_backend_set();
|
||||
let instance = InstanceIdentity::new(config.server.base_url.clone());
|
||||
@@ -83,8 +72,6 @@ pub async fn build_worker(config: &config::AppConfig) -> anyhow::Result<WorkerAp
|
||||
assemble(config, db, instance).await
|
||||
}
|
||||
|
||||
/// Builds the same worker as [`build_worker`] on a caller-provided pool.
|
||||
/// Migrations run on it exactly as they do for the normal path.
|
||||
pub async fn build_worker_on(
|
||||
config: &config::AppConfig,
|
||||
pool: sqlx::SqlitePool,
|
||||
|
||||
Reference in New Issue
Block a user